Applied Design Patterns with Java


Design Patterns share some overriding ideas, which may seem odd, or flawed, or just not-believable at a first encounter. Here are two basic Design Patterns Principles:

  1. Program to an interface and not to an implementation. The core idea here is to start inheritance hierarchies with abstract classes or interfaces, and thus decouple method interfaces from method implementations. Formally, this is known as Polymorphism, and it adds tremendous flexibility and power to designing systems of objects. Component-based development is an example of this.
  2. Favor object composition over inheritance. This seems to contradict the first premise. The core idea here is that inheritance tends to destroy encapsulation and creates dependencies in child classes on parent classes. The preferred solution is to use a Delegate - have a reference in a class to navigate to functionality, rather than inheriting it internally.

We will return to these premises repeatedly in this course.

Prev Next