Sign in to follow this  

class design

This topic is 4256 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

This topic is 4256 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this