Join Jungwoo Ryoo for an in-depth discussion in this video Consistency, part of Python: Design Patterns.
- Other than simply using Design Patterns, there are also universal principles you need to be applying whenever you're coding. Consistency is one of the hallmarks of good software engineering. One of the reasons why we recommend the use of Design Patterns is to promote the consistency of the code. If the same solution is used over and over again to solve the same problem, users need to modify only one piece of code when there is a need for changing the code.
Otherwise, you need to develop different strategies for different solutions throughout the code to accommodate for the same change requirement. The benefit of promoting consistency include reducing the risk of making mistakes, since the same piece of code is used over and over again. Another benefit is increasing the possibility of detecting errors, since more sets of eyes look at the same code and may spot the errors more quickly.
Saving the cost of software development is another benefit, since you simply reuse the well-established design solutions in the form of patterns and their in-house or third-party implementations. A larger scale way of accomplishing consistency is by creating a software architecture and try to stick to it. This could be as simple as identifying a pattern to be used throughout your software in a coherent manner.
Another way of enforcing consistency is the use of frameworks. The frameworks consist of a set of design patterns put together in a specific fashion to accomplish a specific goal. For example, there are frameworks specializing in improving software security, while there are frameworks whose focus is providing a particular set of functionalities, such as building an e-commerce website.
Consistency is one of the most important software engineering principles, and the use of Design Patterns make your job much, much easier to keep your code consistent.
- 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.