Intro
What is a design pattern?
When developing software, you will will notice that a lot of problems recurr frequently. These are called common software design problems. Design patterns are templates for solving common software design problems. They’re not code snippets, but blueprints for organizing code in a way that’s flexible, reusable, and maintainable.
Key ideas
1. They solve recurring problems:
- Example: How do you ensure only one instance of a class exists (like a database connection)? Use the Singleton pattern.
- Example: How do you add features to an object without rewriting it? Use the Decorator pattern.
2. They define relationships between objects:
- Some patterns focus on how objects communicate (e.g., Observer pattern for event-driven systems).
- Others focus on how objects are created (e.g., Factory pattern to hide complex object creation logic).
3. They're common grouped into these categories:
- Behavioral
- Creational
- Structural