Design Patterns

Design Patterns

Creational Patterns

These patterns focus on object creation mechanisms, providing flexibility and decoupling the client code from the specific classes instantiated. Some examples of creational patterns are:

  1. Singleton: Ensures that only one instance of a class exists throughout the program.
  2. Factory: Provides an interface for creating objects, but allows subclasses to decide which class to instantiate.
  3. Builder: Separates the construction of complex objects from their representation, allowing the same construction process to create different representations.
  4. Abstract Factory: Provides an interface for creating families of related or dependent objects without specifying their concrete classes.
  5. Prototype: Creates new objects by cloning existing ones and modifying them as needed.

Structural Patterns

These patterns deal with the composition of classes and objects, focusing on how they can be organized to form larger structures while keeping them flexible and efficient. Some examples of structural patterns are:

  1. Adapter: Converts the interface of one class into another interface that clients expect, enabling classes to work together despite incompatible interfaces.
  2. Decorator: Dynamically adds new behavior to an object by wrapping it with one or more decorator objects.
  3. Composite: Composes objects into tree structures to represent part-whole hierarchies. It lets clients treat individual objects and compositions of objects uniformly.
  4. Proxy: Provides a surrogate or placeholder for another object to control access to it.Facade: Provides a simplified interface to a complex system of classes, making it easier to use and reducing dependencies.
  5. Flyweight: Minimizes memory usage by sharing common data between multiple similar objects.

Behavioral Patterns

These patterns focus on the interaction between objects, defining the communication patterns and responsibilities among them. Some examples of behavioral patterns are:

  1. Observer: Defines a one-to-many dependency between objects, so that when one object changes state, its dependents are notified and updated automatically.
  2. Strategy: Encapsulates interchangeable algorithms within a family of objects, allowing clients to switch between algorithms at runtime.
  3. Iterator: Provides a way to access elements of an aggregate object sequentially without exposing its underlying representation.
  4. Template Method: Defines the skeleton of an algorithm in a base class, with specific steps implemented in subclasses.
  5. Command: Encapsulates a request as an object, allowing parameterization of clients with different requests, queueing, or logging requests, and supporting undoable operations.
  6. State: Allows an object to alter its behavior when its internal state changes.
  7. Chain of Responsibility: Avoids coupling the sender of a request to its receiver by giving more than one object a chance to handle the request.
  8. Mediator: Defines an object that encapsulates how a set of objects interact, promoting loose coupling between them.
  9. Interpreter: Defines a representation of a grammar along with an interpreter that uses the representation to interpret sentences in the language.
  10. Visitor: Separates an algorithm from the objects on which it operates, allowing new operations to be added without modifying the objects.
  11. Memento: Captures and externalizes an object's internal state so that it can be restored later, without violating encapsulation.
  12. Null Object: Provides a default behavior for an interface, effectively representing the absence of an object.

Note: The patterns are organized based on their primary category. However, some patterns may have elements or characteristics that could be classified under multiple categories.

Popular posts from this blog

Atom - Jupyter / Hydrogen

Robson Koji Moriya disambiguation name