Chapter 9. Design Patterns

Table of Contents
Introduction
The FET pattern: data source, data gate, data drain
Command
Abstract Factory
Observer
Visitor
Model-View-Controller (MVC)

Introduction

What is a design pattern?

"Each pattern describes a problem which occurs over and over again in our environment 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 ever doing it same way twice".

A pattern has 4 essential elements:

  • A pattern name

  • The problem and its context, eventually design problems, structures, essential conditions for the use of a pattern.

  • The solution describes the elements that make up the design, their relationship, responsibilities, and collaborations.

  • The consequences are the result and trade-offs of applying the pattern.

Describing Design Patterns

We try to describe our design patterns using a consistent format. Each pattern is divided into sections according to the following template.

Pattern Name and Classification

The pattern's name conveys the essence of the pattern succinctly. A good name is vital, because it will become part of your design vocabulary.

Intent

A short statement that answers the following questions: What does the design pattern do? What is its rationale and intent? What particular design issue or problem does it address?

Motivation

A scenario that illustrates a design problem and how the class and object structures in the pattern solve the problem. The scenario will help you to understand the more abstract description of the pattern.

Applicability

What are the situations in which the design pattern can be applied? What are examples of poor designs that the pattern can address? How can you recognize these situations?

Structure

A graphical representation of the classes in the pattern using a notation based on the UML.

Participants

The classes and/or objects participating in the design pattern and their responsibilities.

Collaborations

How the participants collaborate to carry out their responsibilities.

Consequences

How does the pattern support its objectives? What are the trade-offs and results of using the pattern? What aspect of system structure does it let you vary independently?

Implementation

What pitfalls, hints, or techniques should you be aware of when implementing the pattern? Are there language-specific issues?

Sample Code

Code fragments that illustrate how you might implement the patter in Ada 95. Many patterns are documented very well in other books, so we references to them with one disadvantage that there are only C++ or Smalltalk samples.

Known Uses

Examples of the pattern found in real systems.

Related Patterns

What design patterns are closely related to this one? What are the important differences? With which other patterns should this one be used?