Design Patterns

Knowledge of design patterns is crucial for any kind of serious software development. Let's learn what they are, what they are good for, and the names of, and basic ideas behind, a few of the more popular ones.


"Each pattern describes a problem which occurs over and over again ... and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without doing it the same way twice." -- Christopher Alexander

Design Patterns for Object-Oriented Software

Design Patterns are not analysis patterns, are not descriptions of common structures like linked lists, nore are they detailed application or framework designs. Design Patterns are "descriptions of communicating objects and classes that are customized to solve a general design problem in a particular context." -- Gamma et al.

Good design patterns help make your software more flexible and reusable.

Why study design patterns

Common themes in design patterns

Design patterns are used by experts to make their designs more flexible and reusable, so in studying them you tend to see:

Some real-world examples

The 23 patterns from the book

  Creational Structural Behavioral
Class Factory Method Adapter (class) Interpreter
Template Method
Object Abstract Factory
Adapter (object)
Chain of Responsibility

Patterns are for Reuse

Each pattern lets you vary some aspect of the system.

Causes of redesign and patterns that address them:

Patterns in the Document Editor Case Study

Start by studying the easiest patterns first

Adapter, Decorator, Composite, Observer, Template Method, Factory Method, Abstract Factory, Strategy.

List of the Original 23 Patterns

Purpose Design Pattern Aspect(s) that can vary
Creational Abstract Factory families of product objects
Builder how a composite object gets created
Factory Method subclass of object that is instantiated
Prototype class of object that is instantiated
Singleton the sole instance of a class
Structural Adapter interface to an object
Bridgeimplementation of an object
Compositestructure and composition of an object
Decoratorresponsibilities of an object without subclassing
Facadeinterface to a subsystem
Flyweightstorage costs of objects
Proxyhow an object is accessed; its location
Behavioral Chain of Responsibilityobject that can fulfill a request
Commandwhen and how a request is fulfilled
Interpretergrammar and interpretation of a language
Iteratorhow an aggregate's elements are accessed, traversed
Mediatorhow and which objects interact with each other
Mementowhat private information is stored outside an object, and when
Observernumber of objects that depend on another object; how the dependent objects stay up to date
Statestates of an object
Strategyan algorithm
Template Methodsteps of an algorithm
Visitoroperations that can be applied to object(s) without changing their class(es)