Sobes.tech
Middle

What types of design patterns do you know?

sobes.tech AI

Answer from AI

Design patterns are proven solutions to common development problems. Main types of patterns:

  • Creational:

    • Singleton — guarantees a single instance of a class.
    • Factory Method — creating objects through an interface.
    • Abstract Factory — creating families of related objects.
    • Builder — step-by-step creation of a complex object.
    • Prototype — cloning objects.
  • Structural:

    • Adapter — converts one class interface to another.
    • Decorator — dynamically adds behavior to an object.
    • Proxy — substitute for an object to control access.
    • Composite — tree structure of objects, where individual and composite objects are treated uniformly.
    • Facade — simplified interface to a complex system.
  • Behavioral:

    • Observer — subscribing to events.
    • Strategy — choosing an algorithm at runtime.
    • Command — encapsulating a request as an object.
    • Iterator — sequential traversal of a collection.
    • State — changing object behavior when its state changes.

These patterns help write flexible, maintainable, and extendable code.