Design Patterns
I’ve more or less neglected learning design patterns for as long as I can remember. I know the basics of the basic design patterns, but I never looked into all 23 of them. If you are in the same boat, these series of blogs should give you a brief idea of what they are and how to use them. I will also include UMLs and links to the GitHub repos if you want to take a deeper dive into any particular design pattern.
What are design patterns anyways?
Structuring your code base in a way that you maximize reuse of code and avoid writing duplicate code is very important in software engineering. Erich Gamma, Richard Helm, Ralph Johnson and John Vissides (collectively known as Gang of four) outline this point in their book titled “Design Patterns — Elements of Reusable Object-Oriented Software”. In the book, they introduce the idea of design patterns, a general reusable solution to commonly occurring problems in software design and architecture.
Put simply, design patterns help a designer get a design “right” faster.
However, design patterns are not finished design that you can directly copy to your codebase. They are templates and ideas for how you can solve a problem and minimize future issues.
Classification of Design Patterns
Design patterns are classified in 3 categories:
- Creational design patterns— These design patterns deal with how classes and objects are created and instantiated. They use OOP principle, particularly encapsulation and abstraction, to separate object creation from the rest of the system. This includes —
- Abstract Factory
- Builder
- Factory
- Object Pool
- Prototype
- Singleton - Structural design patterns — These design patterns deal with class and object composition. It uses inheritance to compose interfaces and define ways to compose objects to add new functionality. This includes —
- Adapter
- Bridge
- Composite
- Decorator
- Facade
- Flyweight
- Private Class Data
- Proxy - Behavioral design patterns — These design patterns handle how objects interact with each other. This includes —
- Chain of Responsibility
- Command
- Interpreter
- Iterator
- Mediator
- Memento
- Null object
- Observer
- State
- Strategy
- Template method
- Visitor
Congratulations on making it to the end!!! There will be more blogs with the explanation and examples of the design patterns.