Object-Oriented (OO) Patterns are reusable solutions to common software design problems that occur in object-oriented systems.
👉 Simple idea: Instead of solving the same design problem again and again, we use a proven template (pattern).
A design pattern is NOT code. It is a:
"Blueprint for solving a recurring design problem"
Design patterns are mainly divided into 3 categories:
👉 These patterns deal with how objects are created
Definition: Ensures only one instance of a class exists.
Example:
class Database {
private static Database instance;
}
👉 Only one object is shared globally.
Definition: Creates objects without exposing creation logic.
Example: Car factory → produces different cars
Definition: Builds complex objects step by step.
Example: Burger customization (bun, cheese, sauce)
👉 These patterns deal with how classes and objects are structured
Definition: Converts one interface into another compatible interface.
Example: Mobile charger adapter
Definition: Adds new behavior to an object without changing its structure.
Example: Adding toppings to pizza 🍕
Definition: Provides a simple interface to a complex system.
Example: ATM hides banking system complexity
👉 These patterns deal with how objects interact and communicate
Definition: One-to-many relationship where one object notifies others.
Example: YouTube channel subscription 🔔
Definition: Defines multiple algorithms and selects one at runtime.
Example: Payment methods (Card, UPI, Cash)
Definition: Encapsulates a request as an object.
Example: Remote control buttons 📺
| Feature | Design Pattern | Algorithm |
|---|---|---|
| Purpose | Design solution | Step-by-step logic |
| Level | High-level design | Low-level implementation |
| Focus | Structure & interaction | Computation |
👉 Trick to Remember: "CSB" → Creational, Structural, Behavioral
Open this section to load past papers