Introduction to Design Patterns:
Building Reusable Object-Oriented Software
Overview
- Design OO software is not easy, but design reusable object-oriented software is even
harder.
- You are almost bound to mistake when you first try out your OO design
- However, experienced object-oriented designers do make good designs
- Design patterns are the well documented experience of OO designer.
- These patterns solve specific design problems and make object-oriented designs more
flexible, elegant, and ultimately reusable.
- Once you know the pattern, a lot of design decisions follow automatically.
- Expressing proven techniques as design patterns makes them more accessible to developers
of new systems.
What is a Design Pattern
There are four essential elements:
- Pattern name: to capture a design problem, its solutions and
consequences in a word or two
- Problem: to describe when to apply the pattern
- Solution: to describe the elements that make up the design, their
relationships, responsibilities, and collaborations.
- Consequences: describe the results and trade-offs of applying the
pattern.
Although design patterns supposingly describe object-oriented designs, they are based
on practical solutions that have been implemented using OOP such as C++, Smalltalk and
(Java).
Syntax
We will be using a consistent format to describe a particular Design Patterns
- Pattern Name and Classification
- Intent:
A short statement that states what does the design pattern do, rationale and intent, etc.
- Aka (Also Known As):
The alias or alternative name
- Motivations:
A real scenario that exercise the class and object structure to solve a problem
- Applicability:
The specific domain that the pattern will apply
- Structure:
Graphical representation using CRC cards, OMT or Booch to describe classes and
interactions within the pattern
- Participants:
Listings of classes and / or objects participating in the design pattern and their
responsibilities
- Collaborations:
How the participants collaborate to carry out their responsibilities.
- Consequences:
The results and the trade-offs of using the patterns.
- Implementation:
A checklist of how to build a solution using the design pattern. Listings of pitfalls,
hints or techniques.
- Related Patterns:
Design patterns usually work together to solve a problem. List all the related patterns in
this section.
The Catalog of Design Patterns
- Abstract Factory
- Adapter
- Bridge
- Builder
- Chain of Responsibility
- Command
- Composite
- Decorator
- Facade
- Factory Method
- Flyweight
- Interpreter
- Iterator
- Mediator
- Memento
- Observer
- Prototype
- Proxy
- Singleton
- State
- Strategy
- Template Method
- Visitor
Design Pattern Space
|
|
|
Purpose |
|
|
|
Creational |
Structural |
Behavioral |
Scope |
Class |
Factory Method
|
Adapter |
Interpreter Template Method |
|
Object |
Abstract Factory Builder
Prototype
Singleton |
Adapter Bridge
Composite
Decorator
Facade
Flyweight
Proxy |
Chain of Responsibility Command
Iterator
Mediator
Memento
Observer
State
Strategy
Visitor |
How to Select a Design Pattern
Consider how design patterns solve design problems
Scan Intent sections
Study how patterns interrelate
Study patterns of like purpose
Examine a cause of redesign
Consider what should be variable in your design
How to Use a Design Pattern
Read the pattern once through for an overview.
Go back and study the Structure, Participants, and Collaborations sections.
Look at the Sample Code section to see a concrete example of the pattern in code.
Choose names for pattern participants that are meaningful in the application context.
Define the classes.
Define application-specific names for operations in the pattern.
Implement the operations to carry out the responsibilities and collaborations in the
pattern.