How To Apply Design Patterns when Designing Software
Once you have identified a design pattern that helps solve your problem, this Slideshow illustrates the steps to take to use the pattern effectively:
The following series of images explore how to use a pattern.
The first thing you should do is study the pattern so that you are sure you understand it
Map the generic pattern into your specific problem
Adopting a pattern often requires you to add, remove and reorganize the classes and objects in your system
You will need to implement the pattern in code. This is often the easiest part of programming with patterns.
Describing Design Patterns
How do we describe design patterns? Graphical notations, while important and useful, are not sufficient.
They simply capture the end product of the design process as relationships between classes and objects.
To reuse the design, we must also record the decisions, alternatives, and trade-offs that led to it. Concrete examples are important too, because they help you see the design in action. We describe design patterns using a consistent format and each pattern is divided into sections according to the following template. The template lends a uniform structure to the information, making design patterns easier to learn, compare, and use.
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.
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?
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 understand the more abstract description of the pattern that follows.
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?
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?
What pitfalls, hints, or techniques should you be aware of when implementing the pattern? Are there language-specific issues?
Code fragments that illustrate how you might implement the pattern in C++ or Java.
Examples of the pattern found in real systems. We include at least two examples from different domains.
In the analysis phase, a vague understanding of the problem is transformed into a precise description of the tasks that the software system needs to carry out. The result of the analysis phase is a detailed textual description, commonly called a functional specification, that has the following characteristics:
It completely defines the tasks to be performed.
It is free from internal contradictions.
It is readable both by experts in the problem domain and by software developers.
It is reviewable by diverse interested parties.
It can be tested against reality.
Consider the task of writing a word-processing program.
The analysis phase must define terms, such as fonts, footnotes, multiple columns, and document sections, and the interaction of those features, such as how footnotes in multiple-column text should look on the screen and the printed page. The user interface must be documented, explaining, for example, how the user is to enter and move a footnote or specify the font for footnote numbers. One possible format for an analysis document is a user manual, very precisely worded to remove as much ambiguity as possible.
Another common format for describing the behavior of a system is a set of use cases.
A use case is a description of a sequence of actions that yields a benefit for a user of a system.
At least in principle, it should be possible to enumerate all benefits that a system can confer upon its users and supply use cases that show how they can be obtained. The analysis phase concerns itself with the description of what needs to be done, not how it should be done. The selection of specific algorithms, such as those that insert page breaks or sort the index, will be handled in the implementation phase.
It is possible to use object-oriented techniques in the analysis phase as well as the design phase.
An advantage of that approach is that the object model of the analysis phase can be carried forward to the design phase.
A potential pitfall is that customers of a software product are generally not familiar with the terminology of object orientation.
Clients may not find it easy to tell whether the analysis will lead to a product that satisfies their needs.