Design Patterns

A well-designed application should meet its requirements. It should also be adaptable so that when the real-world requirements change, it can also be changed with minimal effort.

Introduction to Object-Oriented Analysis & Design

The following was taken from "Introduction to Object-Oriented Analysis & Design" available for download from the ProvideX web site.

In 1994, four computer scientists (Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides) authored a ground-breaking book entitled "Design Patterns: Elements of Reusable Object-Oriented Software". In this book, the authors (aka "the Gang of Four" or "GoF") assert that all of the design problems a software engineer faces have been identified and solved. The GoF identify twenty three different patterns, which can be divided into three groups:

Essentially, design patterns are recurring design solutions that may be applied to specific problems. A typical design pattern involves three or more classes. Some patterns are simple and obvious, some are complex and elegant.

Patterns can help software engineers resolve common software problems in a tried-and-true way. A development team that has adapted patterns can easily communicate the intention of their code - it becomes somewhat self-explanatory.

For example, when a developer who is familiar with design patterns encounters an Observer (behavioral pattern) in a program, he or she will not have to wade through the code to determine what it does. The pattern is often easily identified by the naming conventions used in the code, as well as by the intent of the pattern and by the way it works as a known commodity.

Don't confuse design patterns with algorithms or language idioms. A design pattern is a solution that can be applied to a design problem in any object-oriented language. In fact, you are probably using patterns already and may not know it.

The following are the design patterns identified in the original GoF design patterns book.

Creational Structural Behavioral
Factory Method (class scope)
Abstract Factory
Builder
Prototype
Singleton
Adapter (class scope)
Adapter
Bridge
Composite
Decorator
Facade
Flyweight
Proxy
Interpreter (class scope)
Chain of Responsibility
Command
Iterator
Mediator
Memento
Observer
State
Strategy
Visitor

Note: There are also some patterns in common use that do not appear in the list published by the GoF

All design patterns have four characteristics.

Observer Design Pattern

The essence of this pattern is that one or more objects (called listeners or observers) are registered to observe an event which is raised (or triggered) by the observed object (subject).

Observer pattern diagram Observer pattern diagram