Join Jungwoo Ryoo for an in-depth discussion in this video Understanding Pattern context, part of Python: Design Patterns.
- To use design patterns effectively, you need to know the context in which the design patterns work best. It is also important to know what is used to describe the design pattern context. A pattern context consists of the following: participants, quality attributes, forces, and consequences. Participants refer to the classes involved to form a design pattern. These classes involved in the design pattern, they play a different roles to accomplish the goals of the design pattern.
Quality attributes refer to these nonfunctional requirements such as usability, modifiability, reliability, performance, and so on. Quality attributes have an impact on the entire software, and these quality attributes are typically addressed only by the architectural solutions. Forces are various factors or trade-offs you consider when you're trying to adopt a particular design pattern. These forces are typically manifested in quality attributes such as modifiability, usability, reliability, performance, etc.
If you don't reason about these forces very well you may end up facing some unintended consequences. And these consequences could be side effects such as worse performance when you're trying to use one of the design patterns to accomplish better security. The ultimate responsibility really falls on the decision makers who will be choosing a particular design pattern despite the consequences.
Knowing when to use a design pattern and when not to use it, is crucial, especially because the design patterns can cause more problems instead of solving problems when they're misused.
- 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.