Original Post
🔒 Locked
c++ class design
Advertisement
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. :)
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.
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.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement