Jump to content
  • Advertisement
Sign in to follow this  
frogtag

Type Of Class Hierarchy?

This topic is 3411 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

I can't work out the best way to set up my classes. I have these classes: 1) character - the parent class 2) skeleton - has all the info on skeletal animation and graphics 3) eyes - has to do with the program i'm writing where details on the eyes and vision are important. (and future possibility of more classes similiar to eyes.) As you can see the classes are all parts of a character. I want to keep them as 1 entity rather than unconnected classes. My logic is that if you have multiple characters, you want to have their details linked to them. I don't think class inheritance is the way to go, i may be wrong? However I have read about nesting classes. Is this the best approach? Also what about embedded classes?

Share this post


Link to post
Share on other sites
Advertisement
May I ask what other classes may be similar to Eyes? If you're planning on doing something like having different types of Eyes, then I'd create a simple hierarchy for those. That way, you can contain a Skeleton inside a Character and also contain a base class from which Eyes and other classes derive.

Something like this:


class Character
{
public:
Character(Skeleton* s, Vision* v) : skeleton_(s), vision_(v) {}
private:
Skeleton* skeleton_;
Vision* vision_;
};

class Vision
{
public:
// Make your common interface pure virtual.
virtual void Look() = 0;
virtual ~Vision() {}
};

class Eyes : public Vision
{
public:
virtual void Look() { std::cout << "You use your eyes to see an object in the distance." << std::endl; }
};

class InsectEyes : public Vision
{
public:
virtual void Look() { std::cout << "You see everything eight times. Insect eyes are awfully confusing!" << std::endl; }
};



This way you can pass in different types of Vision to your Characters and still use the same interface to work with them.

Share this post


Link to post
Share on other sites
The other classes would be the other senses; eyes or more accurately sight, hearing, touch, smell, taste, perhaps ESP?!

The skeletal class is separate from the above class as its graphically orientated. The senses classes will interact with an simple AI routine. So guess I could use a senses base class?

Share this post


Link to post
Share on other sites
I don't see why not, as long as you can create an interface that will be identical for all senses. It will work as long as you can treat them all in the same way.

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!