c++ class design

Started by
5 comments, last by GameDev.net 18 years, 5 months ago
does anybody know of any good online articles that help teach you how to break up a problem and split it into reusable classes? i am hopeless at splitting into classes and i can't find any papers with good examples. thanks
Advertisement
It depends on what you're coding for as to how you design your classes. Is there anything in particular that you're having trouble coming up with a design for?
:stylin: "Make games, not war.""...if you're doing this to learn then just study a modern C++ compiler's implementation." -snk_kid
not really. i just want to write easier to modify code. and for it to be reusable. my classes always end up massive and unmanageble. frustrating at times. i want to be able to break it down to abstract classes and build it up like that. am i making any sense? i babble a bit. :)
Refactor
Refactor
Refactor
Refactor
For easily reusable/flexible code, strive for the most encapsulation you can. Encapsulation means the implementation is hidden, and only the interace is exposed. Keep all member data private and provide functions to work with that data. The more public/exposed/unencapsulated data you have, the more clients (as in you) rely on that data not to change, meaning they rely on its unflexibility. The more encapsulation you provide, the more opportunity you have to change implementation (faster algorithm, different container, etc.).

This applies to protected data as well as public. Any class that derives from a base class relies on the protected data as much as the public data. In other words, protected data provides as much encapsulation as public data - meaning essentially none. Keep all data private.

EDIT: and listen to Oluseyi.
:stylin: "Make games, not war.""...if you're doing this to learn then just study a modern C++ compiler's implementation." -snk_kid
reading up on refactoring now.

cheers guys :o)
If you do not yet understand the power full of 'virtual', it can help you IMMENSELY. (You could almost create a religion around that word.) When you truly understand that topic, things seem to almost refactor themselves, but it is still a time-consuming, agonizing process, that you wouldn't wish upon your worst enemy at times.

Have fun!

This topic is closed to new replies.

Advertisement