views:

54

answers:

3

Or according to your own experience,

what's your favorite trick ?

A: 

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

Matt Blaine
A: 

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

darren
He likes DONUTS more, but DO Not Use This Saying.
Roger Pate
This is why people end up being crushed when they come out of college and realize that a computer science degree has very little to do with software development.So we're clear: that's a slam on your CSC 110 instructor, not you.
ha, i'm a graduate student here now. I'll let her know you don't approve of her methods :)
darren
+1  A: 

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.