Gang of Four Intro to Design Patterns


**What’s a design pattern?**

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.

An analogy to an algorithm is a cooking recipe: both have clear steps to achieve a goal. On the other hand, a pattern is more like a blueprint: you can see what the result and its features are, but the exact order of implementation is up to you.

**Why should I learn patterns?**

  • 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.

History of GoF

Four authors: Erich Gamma, John Vlissides, Ralph Johnson, and Richard Helm.

  • In 1994, they published Design Patterns: Elements of Reusable Object-Oriented Software, in which they applied the concept of design patterns to programming.
  • The book featured 23 patterns solving various problems of object-oriented design
  • Due to its lengthy name, people started to call it “The Book by the gang of four” which was soon shortened to simply “the GoF book”.

**Criticism of patterns**

  • **Kludges for a weak programming language**
  • **Inefficient solutions**
  • **Unjustified use**
    • If all you have is a hammer, everything looks like a nail

Design Pattern Categories

There are many other unofficial and undocumented patterns out there that you might find useful in certain situations outside of the classic 23. However, all patterns can be categorized by their intent, or purpose. The book covers three of the main groups of patterns, which I will go into more detail in the next blog.

  • Creational Pattern
  • Structural Pattern
  • Behavioral Pattern

Behavioral Design Patterns

Creational Design Patterns

Structural Design Patterns


This post is licensed under CC BY 4.0 by the author.