Or according to your own experience,
what's your favorite trick ?
Or according to your own experience,
what's your favorite trick ?
To steal Trumpi's answer from a similar(?) question:
http://stackoverflow.com/questions/845966/oop-good-class-design/845984#845984
And another answer by philippe:
http://stackoverflow.com/questions/399656/are-there-any-rules-for-oop/399737#399737
In my CSC 110 class I was taught Homer Simpson likes PIE (PIE being the big 3 concepts of object oriented programming).
P = polymorphism I = inheritance E = encapsulation
The #1 principle is encapsulation - at least the colleges have that part right.
Inheritance, polymorphism, cohesion, concision, coupling, dependency, etc... all these things really fall under that one umbrella.
"Encapsulate by practice and expose by need."
The rest pretty much proceeds from there: Limit the number of places that a change forces you to revisit, ideally, every change to behavior would either be the beginning or the end of a chain-reaction (change the test then change the thing it tests) and every change to design would trigger absolutely no consequent changes. This is a reality that is seldom achieved.
"Find what varies and encapsulate it."
Don't use inheritance to give one class the behaviors of another; use delegation in its place. Use inheritance to create abstractions behind which numerous variations live. If you think you have a problem that requires you to degrade design, your problem is probably that, instead, your design needs to improve.
There's probably a good list of OOP code qualities somewhere with good descriptions, so I won't bother to retype it here. Follow those principles, adapt your practices as your situation requires, and you should be pretty good to go.