Design Patterns#

Design patterns are typical solutions to commonly occurring problems in software design. They are like pre-made blueprints that you can customize to solve a recurring design problem in your code.

Why should I learn design patterns?#

The truth is that you might manage to work as a programmer for many years without knowing about a single pattern. A lot of people do just that. Even in that case, though, you might be implementing some patterns without even knowing it. So why would you spend time learning them?

  • Design patterns are a toolkit of tried and tested solutions to common problems in software design. Even if you never encounter these problems, knowing patterns is still useful because it teaches you how to solve all sorts of problems using principles of object-oriented design.

  • Design patterns define a common language that you and your teammates can use to communicate more efficiently. You can say, “Oh, just use a Singleton for that,” and everyone will understand the idea behind your suggestion. No need to explain what a singleton is if you know the pattern and its name.

Classification of patterns#

Design patterns differ by their complexity, level of detail and scale of applicability to the entire system being designed. I like the analogy to road construction: you can make an intersection safer by either installing some traffic lights or building an entire multi-level interchange with underground passages for pedestrians.

The most basic and low-level patterns are often called idioms. They usually apply only to a single programming language.

The most universal and high-level patterns are architectural patterns. Developers can implement these patterns in virtually any language. Unlike other patterns, they can be used to design the architecture of an entire application.

In addition, all patterns can be categorized by their intent, or purpose. This book covers three main groups of patterns:

Creational patterns#

These patterns provide various object creation mechanisms, which increase flexibility and reuse of existing code.

Structural patterns#

These patterns explain how to assemble objects and classes into larger structures while keeping these structures flexible and efficient.

Behavioral patterns#

These patterns are concerned with algorithms and the assignment of responsibilities between objects.

Bonus Material#

  • Classic Design Patterns: Where Are They Now - Brandon Rhodes - code::dive 2022

    • By Raymond Hettinger

    Classic Design Patterns: Where Are They Now