Site Archive (Complete)
Architecture Blog: Object-Oriented Principles
Architecture & Design
PATTERN LANGUAGE

Modeling, Managing, Making it Right.

by Jonathan Erickson
IF YOU BUILD IT

... Will they Come?

by Arnon Rotem-Gal-Oz
May 26, 2006

Object-Oriented Principles

It's sad to say, but the 7 Deadly Sins of Design are widely practiced.

One reader even commented that he has seen all of the first 6 in a single project--definitely more prevalent than we want. On many occasions, I've even seen these types of problems in designs made by senior programmers.

Trying to think of why and how this happens, it seems at least some of the problem can be traced to how object orientation is taught. Programming courses usually focus on the syntax and mechanics of OO in general, and the programming language being taught in particular. Attending class, you hear a lot about objects, classes, state, methods, and constructors. Courses also teach you about inheritance, polymorphism, and encapsulation. Still, the focus is mostly on what it is and how to do it in insert your favorite language here programming language, but not on the motivations. Another problem is that courses usually talk about synthetic examples (shapes, pets, etc.), not real-world problems.

The same is true to "design courses." Often, these courses only teach UML syntax, not how to design or analyze. Or they stress design patterns and their implementation but not the motivations for the solution; for example, use cases is a functional decomposition technique. I've seen many developers "analyze" use cases and come up with a class model where the logic of what should be a single class is fragmented in per-use case classes.

This is a generalization, and I am sure there are some excellent courses out there. Moreover, I probably haven't seen enough courses to really pass judgment. However, I have had the chance to work with many developers and the "knowledge patterns" described above are recurrent.

Anyway, there is no point crying over spilled milk. Instead of just complaining, I thought I'll take the same path I took with the fallacies and dedicate some of the future posts to some of the principles that do lead to better designs. Specifically these posts will talk about:

  • Protected Variation/Open Closed Principle
  • Inversion Of Control
  • Cohesion--Single Responsibility Principle
  • Interface Segregation principle
  • Design-by-Contract/Liskov substitution principle
  • Dependency Inversion principle
  • Dependency Injection
  • YAGNI

Note that these principles are not my invention. These principles are the work of people like Bertrand Meyer, Robert C. Martin, Barbara Liskov, Martin Fowler, Tom Demarco, David Parnas, and probably a few others I don't know since some of these principles are 20 years or more old.

Posted by Arnon Rotem-Gal-Oz at 06:42 AM  Permalink




 
INFO-LINK


Related Sites: DotNetJunkies, SD Expo, SqlJunkies