Sign in to follow this  
shermy101

c++ class design

Recommended Posts

shermy101    127
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

Share this post


Link to post
Share on other sites
stylin    758
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?

Share this post


Link to post
Share on other sites
shermy101    127
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. :)

Share this post


Link to post
Share on other sites
stylin    758
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
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!

Share this post


Link to post
Share on other sites

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