03design_pattern_intro
Lecture_2_design_pattern_intro
Design Pattern Overview
Q:What does a pattern do?
A:Documents a recurring
重复出现的 problem/solution paring within a given context
Essential elements
Pattern name
- Used to provide a single and meaningful name to the pattern which defines a design problem and a solution for it.
- Naming a design pattern helps itself to be referred to others easily.
- Allows easy documentation
- Right vocabulary word makes it easier to think about the design.
Problem
- An abstract description.
- Describes when to apply the pattern.
- Explains the context.
- Might describe specific design problems such as how to represent algorithms as objects.
- Might describe a 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
Solution
- describes the elements that make up the design, their relationships, responsibilities, and collaborations协作.
- Not the complete code, but it works as a template which can be fulfilled with code.
- Abstract description of the problem and how a general arrangement of elements (classes and objects in our case) solves it.
Results and consequences of applying the pattern.
- The consequences for software often concern space and time tradeoffs.
- They may address language and implementation issues as well.
- Reuse is an important factor in object-oriented design
- So, 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.
Patterns
Solutions drawn from experience that were then documented.