class design

Started by
2 comments, last by jollyjeffers 18 years ago
if I put a function into a class, but the function will depend some other class. for example: class skinedmesh { } skinmesh should a resource class. it has not render function. now I add a new function draw, it will depend IDirect3DDevice9 (I know you can pass parameter) so I must add a member data IDirect3DDevice9 m_device to skinnedmesh. how to handle this problem?
Advertisement
Quote:Original post by derek7
if I put a function into a class, but the function will depend some other class.

for example:

class skinedmesh
{

}

skinmesh should a resource class. it has not render function.

now I add a new function draw, it will depend IDirect3DDevice9 (I know you can pass parameter)
so I must add a member data IDirect3DDevice9 m_device to skinnedmesh.

how to handle this problem?
Either don't store the device pointer, but use a singleton or something to gain access to it when you want, or just store it in the class or base class.

I don't see why it's a problem, unless you have a lot of dependencies, in which case you should re-organise your code anyway.
Quote:Original post by Evil Steve
Quote:Original post by derek7
if I put a function into a class, but the function will depend some other class.

for example:

class skinedmesh
{

}

skinmesh should a resource class. it has not render function.

now I add a new function draw, it will depend IDirect3DDevice9 (I know you can pass parameter)
so I must add a member data IDirect3DDevice9 m_device to skinnedmesh.

how to handle this problem?
Either don't store the device pointer, but use a singleton or something to gain access to it when you want, or just store it in the class or base class.

I don't see why it's a problem, unless you have a lot of dependencies, in which case you should re-organise your code anyway.


good tips.
It just a example, I just use device pointer to demostratation.
I just wanna how to re-organise your code.
divide it to base or super class.
use parameter to passin.
use singleton and other tech that work.
use........
anyway just keep class simple and do one thing and do not depend many thing.
I'm going to push this over to General Programming for you. I think you'll get a better answer by having it there...

If you're trying to work out a good way of designing your class, then you might want to look into design patterns - they can be a very useful starting point when it comes to this sort of problem [smile]

Another idea that can work is to use UML (or similar) modelling packages (e.g. Microsoft Office's Visio) and draw up a number of prototype models. See which one is the simplest to work with and suits your desired goals...

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

This topic is closed to new replies.

Advertisement