Monday, September 24, 2007

Design Principles and Patterns

Several hours ago I started to read Head First Design Patterns. Although I am only several chapters into the book my understanding of patterns is already broadening. As I read Head First Design Patterns I am increasing my "programmers vocabulary". This means that will be able to speak more fluently with other software developers. Rather than going into a verbose conversation about the details of a solution I can simply spew out the name of a design pattern.

Head First Design Patterns has enlightened me as to why design patterns are important. A common misconception is that patterns are nothing more than using object oriented design principles. Not all design patterns are obvious, even those who are well versed in object oriented programming may not be able to reproduce many of these design patterns. By understanding design patterns you can jump right to creating proven solutions that work. Needless to say good OO skills are always necessary. After all OO principles are the basis upon which design patterns are built upon on.

Here are a few design principles that I have been introduced to.

  1. Take what varies and encapsulate it, so it does not affect the rest of your code.

  2. Program to an interface not to an implementation.

    The one misconception with this design principle is that you must use an interface. In fact this principle refers to using a super type in place of a concrete type. Hence, you could replace the world interface for super type. Program to an super type not to an implementation.

  3. Favor composition over inheritance.

  4. Strive for loosely coupled designs between objects that interact.

  5. Classes are open for extension, but closed for modification.

No comments: