Jump to content
  • Advertisement
Sign in to follow this  
derek7

class design

This topic is 4479 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
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.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!