|Lesson 4||What makes up a design pattern?|
|Objective||List the four key elements of a design pattern. |
Design Pattern Components
Design patterns are a means to communicate, identify, and remember solutions to common problems.
Each pattern names, explains, and evaluates a solution to a common problem.
Each design pattern has four essential elements:
Behavioral Creational Structural Diagram.
It is not possible to do a formal big-O analysis
of different patterns as it is with algorithms,
because patterns leave too much unspecified.
However, it is possible to make general choices for what trade-offs do exist and which patterns are more suitable for which circumstances.
4 Elements of a Pattern
In general, a pattern has four essential elements:
- The pattern name is a handle we can use to describe a design problem, its solutions, and consequences in a word or two.
Naming a pattern immediately increases our design vocabulary and allows us to design at a higher level of abstraction.
Having a vocabulary for patterns lets us talk about them with our colleagues, in our documentation, and even to ourselves. It makes it easier to think about designs and to communicate them and
their trade-offs to others. Finding good names has been one of the hardest parts of developing our catalog.
- The problem describes when to apply the pattern and explains the problem and its context. It might describe specific design problems such as how to represent algorithms as objects.
In addition, it might describe class or object structures that are symptomatic of an inflexible design. Sometimes the problem will include a list of conditions that must be met before it makes sense to apply the pattern.
- The solution describes the elements that make up the design, their relationships, responsibilities, and collaborations.
The solution does not describe a particular concrete design or implementation, because a pattern is like a template that can be applied in many different situations.
Instead, the pattern provides an abstract description of a design problem and how a general arrangement of elements (classes and objects in our case) solves it.
- The consequences are the results and trade-offs of applying the pattern.
Though consequences are often unvoiced when we describe design decisions, they are critical for evaluating design alternatives and for understanding
the costs and benefits of applying the pattern. The consequences for software often concern space and time trade-offs and may address language and implementation issues as well.
Since reuse is often a factor in object-oriented design, the consequences of a pattern include its impact on a system's flexibility, extensibility, or portability.
Listing these consequences explicitly helps you understand and evaluate them.