Join Jungwoo Ryoo for an in-depth discussion in this video Working with Pattern language, part of Python: Design Patterns.
- The process of mastering important terms used in describing Design Patterns is similar to learning a new language. This is why we refer to these terms as what constitutes a Pattern Language. A Pattern Language consists of name, context, problem, solution, and related patterns. The names of patterns should capture the gist of the pattern, and these names become an essential part of a vocabulary during the design process.
Therefore, they need to be especially meaningful and memorable. The context provides a scenario in which these patterns may be used. The context also provides more insights on when to use the pattern and when not to use the pattern. The problem part of the pattern description describes a design challenge the pattern is trying to address. And the solution part of the pattern description specifies the pattern itself. The patterns are specified in terms of their structures and behaviors.
The structure in this case specifies the relationships in between the elements used in the pattern. The behaviors specify all the interactions in between these elements used in the pattern. The last part of the pattern language is the related patterns. These lists other patterns used together with the pattern being described, or similar but different patterns. It is important in these related patterns sections of the pattern descriptions, to describe exactly what these subtle differences in between the patterns being described.
This sums up a typical pattern language. In fact, this is the pattern language we'll be using to describe the patterns in this course. In addition, once you get the handle of the pattern language, you should be able to define your own pattern if necessary.
- Understanding design patterns
- Best design practices: consistency, completeness, and correctness
- Working with creational patterns
- Working with structural patterns
- Working with behavioral patterns
Skill Level Intermediate
Q: In the strategy pattern example, why does the code keep executing the default function rather than the alternate?
A: The programming demonstration skips the step of defining what the strategy pattern should be when an alternate function name is provided
as an argument as shown below.