Junior — Middle
Can you list the main patterns used in object-oriented programming?
sobes.tech AI
Answer from AI
The main design patterns used in object-oriented programming (OOP) include:
- Singleton — guarantees that a class has only one instance and provides a global point of access to it.
- Factory Method — defines an interface for creating an object, allowing subclasses to alter the type of objects that will be created.
- Observer — allows objects to subscribe to events of another object and receive notifications of changes.
- Decorator — dynamically adds responsibilities to objects by wrapping them.
- Strategy — defines a family of algorithms, encapsulates each one, and makes them interchangeable.
- Adapter — allows objects with incompatible interfaces to work together.
- Command — encapsulates a request as an object, allowing parameterization of clients with different requests.
These patterns help create flexible, extensible, and maintainable application architectures.