- Bitsbyte
- Posts
- Software design patterns
Software design patterns
Design patterns offer reusable solutions to frequently encountered problems in software design, enhancing the modularity, flexibility, and maintainability of your code.
It is categorized into three main types: Creational, Structural, and Behavioral patterns. Each category addresses different aspects of software design.
1. Creational Patterns
These patterns deal with object creation mechanisms, trying to create objects in a manner suitable to the situation.
Patterns | Description |
---|---|
Singleton Pattern | Ensures a class has only one instance and provides a global point of access to it. |
Factory Method Pattern | Defines an interface for creating an object, but let’s subclasses alter the type of objects that will be created. |
Abstract Factory Pattern | Provides an interface for creating families of related or dependent objects without specifying their concrete classes. |
Builder Pattern | Separates the construction of a complex object from its representation so that the same construction process can create different representations. |
Prototype Pattern | Specifies the kinds of objects to create using a prototypical instance and creates new objects by copying this prototype. |
2. Structural Patterns
These patterns deal with object composition or the way to assemble objects and classes into larger structures while keeping these structures flexible and efficient.
Patterns | Description |
---|---|
Adapter Pattern | Allows incompatible interfaces to work together by converting the interface of a class into another interface that a client expects. |
Composite Pattern | Composes objects into tree structures to represent part-whole hierarchies. It lets clients treat individual objects and compositions of objects uniformly. |
Proxy Pattern | Provides a surrogate or placeholder for another object to control access to it. |
Decorator Pattern | Allows behavior to be added to an individual object, dynamically, without affecting the behavior of other objects from the same class. |
Facade Pattern | Provides a simplified interface to a complex subsystem. |
Flyweight Pattern | Reduces the cost of creating and manipulating a large number of similar objects. |
Bridge Pattern | Decouples an abstraction from its implementation so that the two can vary independently. |
3. Behavioral Patterns
These patterns are concerned with algorithms and the assignment of responsibilities between objects.
Patterns | Descriptions |
---|---|
Observer Pattern | Defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. |
Strategy Pattern | Defines a family of algorithms, encapsulates each one, and makes them interchangeable. |
Command Pattern | Encapsulates a request as an object, thereby allowing for parameterization of clients with queues, requests, and operations. |
Chain of Responsibility Pattern | Passes a request along a chain of handlers. Each handler can either handle the request or pass it to the next handler in the chain. |
Mediator Pattern | Defines an object that encapsulates how a set of objects interact. This pattern promotes loose coupling by keeping objects from referring to each other explicitly. |
Memento Pattern | Provides the ability to restore an object to its previous state (undo via rollback). |
State Pattern | Allows an object to alter its behavior when its internal state changes. The object will appear to change its class. |
Template Method Pattern | Defines the skeleton of an algorithm in the superclass but let’s subclasses override specific steps of the algorithm without changing its structure. |
Visitor Pattern | Represents an operation to be performed on the elements of an object structure. It lets you define a new operation without changing the classes of the elements on which it operates. |
Interpreter Pattern | Given a language, defines a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language. |
Iterator Pattern | Provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation. |