Middle
What design patterns do you know?
sobes.tech AI
Answer from AI
Creational:
- Factory Method: Defines an interface for creating an object but allows subclasses to decide which class to instantiate.
- Abstract Factory: Provides an interface for creating families of related or dependent objects without specifying their concrete classes.
- Builder: Separates the construction of a complex object from its representation, allowing the same construction process to create different representations.
- Prototype: Creates new objects by copying an existing instance.
- Singleton: Ensures a class has only one instance and provides a global point of access to it.
Structural:
- Adapter: Converts the interface of a class into another interface clients expect.
- Bridge: Decouples an abstraction from its implementation so that the two can vary independently.
- Composite: Composes objects into tree structures to represent hierarchies part-whole. Composite lets clients treat individual objects and compositions uniformly.
- Decorator: Adds responsibilities to objects dynamically. It is a flexible alternative to subclassing for extending functionality.
- Facade: Provides a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.
- Flyweight: Used for efficient sharing of large numbers of similar objects.
- Proxy: Provides a surrogate or placeholder for another object to control access to it.
Behavioral:
- Chain of Responsibility: Passes requests along a chain of handlers. Each handler decides either to process the request or to pass it to the next handler in the chain.
- Command: Encapsulates a request as an object, allowing parameterization of clients with different requests, queuing of requests, and support for undoable operations.
- Iterator: Provides a way to access the elements of a collection sequentially without exposing its underlying representation.
- Mediator: Defines an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly.
- Memento: Without violating encapsulation, captures and externalizes an object's internal state so that the object can be restored to this state later.
- Observer: Defines a one-to-many dependency between objects so that when one object changes its state, all its dependents are notified and updated automatically.
- State: Allows an object to alter its behavior when its internal state changes. The object will appear to change its class.
- Strategy: Defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
- Template Method: Defines the skeleton of an algorithm in a method, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing its structure.
- Visitor: Represents an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates.
Besides the Gang of Four (GoF) pattern templates, there are other categories such as enterprise integration patterns or microservice patterns. Additionally, architectural patterns like MVC, MVP, MVVM are also frequently used.