Skip to main content
gamedev.net
🔒 Locked

c++ class design

Started by shermy101 5 replies 950+ views
Original Post
shermy101
shermy101
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
stylin
stylin
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
shermy101
shermy101
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. :)
stylin
stylin
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
shermy101
shermy101
reading up on refactoring now.

cheers guys :o)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.