Good OO is NOT Flat
Published: December 08, 2008
Good OO (object oriented) design is not flat. It is 3d and sometimes even 4d in nature. The problem with most object designs is that they are based on the concept of an object. Objects are too constrained. Too often, an object is demoted to the thing that holds the data. People need to get over that idea. OO is simply a way to organize your code into tools that can be reused. The power of OO is found when you use it to create building blocks and tools. Objects are nice, but you really should be intentionally creating re-usable, modular, code! An object is a byproduct of that organizational style. You are programming related functionality in a multi-dimensional manner.
Consider interfaces that allow "horizontal" relationships. An interface is considered part of good OO design. With it, you can relate things that are not related "vertically" via traditional inheritance. If your "object" has legs, then implement the legs interface. Now everyone else can use them... e.g. Object.Legs.Walk, Object.Legs.Run. Perhaps your animal doesn't know how to run? Then let it walk instead :) Now your arthropoda spider and your chordata ape can both walk even though they are from different phylums. It's cross domain functionality.
Excellent programmers understand this distinction. I've seen too many good OO designs muddied by people who still live in a functional/procedural world. This is possible because OO simply extends the procedural model. To be an OO programmer does not imply understanding of OO. In fact, it is possible to program as in the past and completely miss the benefits that OO can give!
Warning signs of bad OO programming ... hmmm, sounds just like bad procedural programming...
- Repeated blocks code
- A single line of code repeated 10s of times.
- GoTo ... LOL :)