Sign in to follow this  

Design problems:'(

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

Heya, I have a little problem. I am getting fairly decent at programming(C++ and dx) and ive written a tile engine and some gfx demos before, but my problem is this. I learned "c with classes" and im only now getting into oop design, and my problem is Im having a hard time designing things. Like my Battle system class, it needs to have information from the enemy class to know that enemy it should draw, etc. So should battle be derived from enemy? That sounds blatantly wrong, so things like that are slowing me down. I can write things fast if i break the "oop" style of things but that will screw me in the long run. My question is how did you all learn/master the oop style of things? Im just having problems developing the mind state and I was wondering if you could give me some tips to help speed me along. Ive learned polymorphism, inheritance etc, but that doesnt mean jack if I cant apply them in a design. Thanks for any help.

Share this post


Link to post
Share on other sites
Quote:
Original post by Mathius20
Heya, I have a little problem. I am getting fairly decent at programming(C++ and dx) and ive written a tile engine and some gfx demos before, but my problem is this. I learned "c with classes" and im only now getting into oop design, and my problem is Im having a hard time designing things. Like my Battle system class, it needs to have information from the enemy class to know that enemy it should draw, etc. So should battle be derived from enemy? That sounds blatantly wrong, so things like that are slowing me down. I can write things fast if i break the "oop" style of things but that will screw me in the long run. My question is how did you all learn/master the oop style of things? Im just having problems developing the mind state and I was wondering if you could give me some tips to help speed me along. Ive learned polymorphism, inheritance etc, but that doesnt mean jack if I cant apply them in a design. Thanks for any help.


check your privet messages...

if you havent gotten the message yet just add me

msn: coolguy_5000@hotmail.com

emails the same

Share this post


Link to post
Share on other sites
I had a little trouble understanding what the aim is of your Battle class there. What does it do? What information does it need?

You definitely don't need it to be derived from enemy. At most, you'll probably pass a pointer to an Enemy class into it - probably something along the lines of myBattle->SetEnemy( *myEnemy );

That's how I'd do it based on the information you've given us so far anyway. Doing it like that, you can then store the pointer that you've been given into a member variable of your Battle class, and do something like m_Enemy->Draw(); - where Draw() would be a function of your Enemy class.

Hope I've explained this well enough for you to follow, someone else could probably make it easier to understand but it's still too early in the morning for me :D

I can't really say I've learned OOP properly myself yet, I'm just working through it as well, but what I've told you is the best way I've figured out so far. Oh, if you wanted multiple enemies, you'd probably have some sort of list or vector in your Battle class, and a function to add them to it... something like myBattle->AddEnemy( *myEnemy ); Then, when you kill them off (or they run away or something) you could call another function to take care of that :)

Share this post


Link to post
Share on other sites
Yea I was gonna mention i was thinking of using a pointer, but I jsut kinda wanted to convey i didnt really know wth im doing with oop in general lol. I can set up basic oop design, but i look at like peoples engines and its so well designed and its like "how do i design that" Like do these pl do it all int heir head on the fly, or write everything down, etc. I just wanna be able to design really solid code that makes people say "wow thats nice" thx for the reply

Share this post


Link to post
Share on other sites
I think most of us (people reading this forums) are thinking that they had to learn how to write compact and well-defined inheritance through years of experience. So they (or atleast me) dont have any good shortcuts to show you.

The only tip that comes to my mind is that a base class is usually, if not always, more conceptual and abstract than the classes inheriting from it. Im sure you have noticed ^^

Share this post


Link to post
Share on other sites

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