Join Jungwoo Ryoo for an in-depth discussion in this video What is a design pattern?, part of Python: Design Patterns.
- When developing software, you'll often observe the same problem occurring over and over again. These recurring problems imply that there may already be well-known solutions to them. This is why we need a design pattern. Design patterns, in short, are well-known solutions to recurring problems. These are widely accepted solutions by the software development community. Then why do we use design patterns? Here are some motivations behind the use of design patterns.
First of all, there's no need to reinvent the wheel and waste your time when there's a perfect solution for you out there. Secondly, design patterns allow to us reuse these design ideas and also encourage us to use the best practices which in turn lowers the cost and promotes the higher quality of software you're developing. Let's have a brief history lesson on design patterns. The creator of this concept, design patterns, is considered to be Christopher Alexander who is a building architect who has nothing to do with software development.
The idea of these design patterns were then picked up by the software development community especially by the Gang of Four. Design patterns got even more popular by the publication of this book called Design Patterns by Gamma and his colleagues. Here are some important characteristics of design patterns you need to be aware of. First of all, design patterns are language neutral because you want to be using these design practices regardless of what language you are using at the moment.
Secondly, design patterns are dynamic because there are always new design patterns coming out and you could be also revising the existing design patterns, if there is a need. Finally, design patterns are intentionally incomplete to promote customization. You should be able to customize your design patterns if there is a need. These days it is a must for professional software developers to master design patterns partly because these patterns are becoming a core vocabulary when discussing design decisions for a software application among seasoned software developers.
- 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.