Senior
What GoF patterns do you know?
sobes.tech AI
Answer from AI
GoF (Gang of Four) patterns are classic design patterns described in the book "Design Patterns" by four authors. Main groups and examples of patterns:
-
Creational:
- Singleton — ensures a class has only one instance.
- Factory Method — creates objects through an interface, allowing subclasses to decide which class to instantiate.
- Abstract Factory — creates families of related objects.
- Builder — step-by-step creation of a complex object.
- Prototype — creating objects through cloning.
-
Structural:
- Adapter — converts the interface of a class into another interface.
- Composite — composes objects into tree structures.
- Decorator — adds behavior to an object dynamically.
- Facade — simplifies the interface of a complex subsystem.
- Proxy — acts as a substitute for an object, controlling access to it.
- Bridge — separates an abstraction from its implementation.
- Flyweight — saves memory by sharing common data.
-
Behavioral:
- Observer — subscribes to events and notifies.
- Strategy — chooses an algorithm at runtime.
- Command — encapsulates a request as an object.
- Iterator — provides sequential access to collection elements.
- Mediator — centralizes interaction between objects.
- State — changes object behavior when changing state.
- Template Method — defines the skeleton of an algorithm.
- Visitor — separates algorithms from data structures.
These are just the main patterns that are often used in Java and other OOP languages.