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
- Chain Of Responsibility Pattern (yet to start)
- Command Pattern (yet to start)
- Iterator Pattern (yet to start)
- Mediator Pattern (yet to start)
- Memento Pattern (yet to start)
- Observer Pattern ( 4 yet to start)
- Visitor Pattern (yet to start)
- Strategy Pattern ( 5 yet to start)
- State Pattern (yet to start)
- Template Method Pattern (yet to start)
Creational Design Patterns
- Simple Factory Pattern (yet to start)
- Factory Method Pattern ( 2 yet to start)
- Abstract Factory Pattern (yet to start)
- Builder Pattern (yet to start)
- Prototype Pattern (yet to start)
- Singleton Pattern ( 1 yet to start)
Structural Design Patterns
- Adapter Pattern (3 yet to start)
- Bridge Pattern (yet to start)
- Composite Pattern (yet to start)
- Decorator Pattern (yet to start)
- Facade Pattern (yet to start)
- Flyweight Pattern (yet to start)
- Proxy Pattern (yet to start)