Sobes.tech
Junior

What design patterns do you know?

sobes.tech AI

Answer from AI

Of course. I will list the main design patterns in Java:

Creational:

  • Singleton: Ensures 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 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 so that the same construction process can create different representations.
  • Prototype: Defines an interface for creating copies of objects through cloning.

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.
  • Decorator: Dynamically adds responsibilities to an object by wrapping it.
  • Facade: Provides a unified interface to a set of interfaces in a subsystem.
  • Flyweight: Uses sharing to support large numbers of fine-grained objects efficiently.
  • Proxy: Provides a surrogate or placeholder for another object to control access to it.

Behavioral:

  • Chain of Responsibility: Passes requests along a chain of potential handlers.
  • Command: Encapsulates a request as an object, allowing parameterization of clients with different requests, queuing of requests, or operations like undo.
  • Interpreter: Defines a grammatical representation for a language and an interpreter to evaluate sentences in that language.
  • Iterator: Provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation.
  • Mediator: Defines an object that encapsulates how a set of objects interact.
  • Memento: Saves and restores an object's previous state without exposing its implementation details.
  • Observer: Defines a one-to-many dependency so that when one object changes state, all its dependents are notified and updated automatically.
  • State: Allows an object to alter its behavior when its internal state changes.
  • Strategy: Defines a family of algorithms, encapsulates each one, and makes them interchangeable.
  • Template Method: Defines the skeleton of an algorithm in an operation, deferring some steps to subclasses.
  • Visitor: Represents an operation to be performed on elements of an object structure. It lets you define a new operation without changing the classes of the elements.

Additionally, I am familiar with more specific patterns used in particular development areas, such as MVC, MVP, MVVM (for presentation), as well as integration patterns like Publisher/Subscriber.