This repository is create to understand the design pattern used in building an efficient application. It will help to avoid redundancy and write a clean code.
Deals with object creation.
- Singleton
Ensures a class has only one instance and provides a global access point.
Example: Logging, Database Connection, Caching
- Factory Method
Defines an interface for creating objects, but lets subclasses decide which class to instantiate.
Example: Frameworks, extensible libraries.
- Abstract Factory
Creates families of related objects without specifying their concrete classes.
Example: UI toolkits (different themes), cross-platform apps.
- Builder
Separates object construction from its representation.
Example: Constructing complex objects (e.g. query builders, HTTP requests)
- Prototype
Creates new objects by copying an existing object.
Example: Expensive object creation scenarios.
Deal with object composition and structure.
- Adapter
Allows incompatible interfaces to work together.
Example: Integrating third-party libraries.
- Decorator
Adds behavior to objects dynamically without modifying their code.
Example: Middleware, logging, validation layers.
- Facade
Provides a simplified interface to a complex subsystem.
Example: API wrappers, service layers.
- Proxy
Provides a placeholder for another object to control access.
Example: Lazy loading, access control, remote services.
- Composite
Treats individual objects and compositions uniformly.
Example: Tree structures (UI components, file systems).
Deal with communication between objects
- Observer
Defines a one-to-many dependency so when one object changes state, all dependents are notified.
Example: Event systems, UI updates
- Strategy
Defines a family of algorithms and makes them interchangeable.
Example: Payment methods, sorting strategies.
- Command
Encapsulates a request as a object.
Example: Undo/redo systems, task queues.
- State
Allows an object to change its behavior when its internal state changes.
Example: Workflow engines, state machines
- Template Method
Defines the skeleton of an algorithm in a method but lets subclasses override steps.
Example: Framework base classes.
- MVC - (Model-View-Controller)
MVC separates an application into three components:
- Model -> Business logic + data
- View -> UI (what the user sees)
- Controller -> Handles user input and coordinates between Model and View.
- MVVM - (Model-View-ViewModel)
MVVM improves on MVC, especially for UI-heavy applications.
- Model -> Data + business logic
- View -> UI
- View Model -> Connects View and Model, handles UI logic
- Repository Pattern
The Repository Pattern abstracts data access logic.
- Dependency Injection (DI)
Instead of a class creating its own dependencies, they are injected from outside.
- Event-Driven Architecture (EDA)
Components communicate using events, not direct calls.
- Microservices Architecture
Instead of building one big application (monolith), you build many small independent services.