Factory: Creates objects without specifying th exact class. This pattern makes code flexible and easier to extend, like a factory producing different products.
Observer: Enables objects (observers) to watch changes in another object (subject). When the subject changes, observers are notified automatically, like subscribing to updates.
Singleton: Ensures a class has only one instance accessible globally, useful for shared resources like databases. Think of it as “the one and only.”
Builder: Constructs complex objects step-by-step. Similar to assembling LEGO bricks, this pattern makes it easy to build intricate objects.
Adapter: Converts one interface into another expected by clients, making incompatible components work together. It bridges the gap between different interfaces.
Decorator: Dynamically adds responsibilities to objects without changing their code. Itโs like adding toppings to a pizza, offering a flexible alternative to subclassing.
Proxy: Acts as a virtual representative, controlling access to an object and adding functionality, like lazy loading.
Strategy: Allows selecting algorithms at runtime, enabling flexible switching of strategies to complete a task. Ideal for situations with multiple ways to achieve a goal.
Command: Encapsulates requests as objects, allowing parameterization and queuing, like a to-do list for programs.
Template: Defines the structure of an algorithm with overridable steps, useful for reusable workflows.
Iterator: Provides a way to access elements of a collection sequentially without exposing its underlying structure, like a “tour guide” for collections.
State: Allows an object to change behavior based on its internal state, keeping code organized as different states accumulate. Think of it as a traffic light guiding behavior.