Join Jungwoo Ryoo for an in-depth discussion in this video Types of design patterns, part of Python: Design Patterns.
- There are mainly three different types of design patterns. One is Creational, the other is Structural, and another one is Behavioral. The Creational design patterns are mainly used to create objects in a systematic way. The main benefit behind these Creational Patterns lies in its flexibility. For example, different subtypes of objects from the same classes can be created at runtime when you use these Creational Patterns.
Structural Patterns are used to establish these useful relationships between software elements or components in certain settings or configurations. The goal here is mainly to accomplish certain functional or nonfunctional requirements. Therefore, these efforts to accomplish these different goals typically lead to different structures implemented in Structural Patterns. Behavioral Patterns are the best practices of how you make your objects interact with each other.
The focus here is really defining the protocols in between these objects when they're trying to work together to accomplish a common goal. There are some important object-oriented mechanisms or concepts that are used to develop these design patterns. For example, in the Creational Patterns, Polymorphism is often used. Structural Patterns take advantage of Inheritance a lot. Behavioral Patterns heavily use methods and their signatures. Interfaces are used across all these different types of design patterns.
Knowing the design pattern types is helpful, especially because it allows you to more quickly locate the design patterns you're looking for.
- 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.