Sobes.tech
Junior — Middle

Can you name the main structural patterns in object-oriented programming?

sobes.tech AI

Answer from AI

The main structural patterns in object-oriented programming help organize classes and objects to simplify structure and increase flexibility. They include:

  • Adapter — allows objects with incompatible interfaces to work together.
  • Decorator — dynamically adds new responsibilities to objects.
  • Facade — provides a simplified interface to a complex subsystem.
  • Proxy — controls access to another object.
  • Composite — allows grouping objects into a tree structure and working with them uniformly.
  • Bridge — separates abstraction and implementation so they can be changed independently.

Example of using the Adapter pattern in JavaScript:

class OldSystem {
  specificRequest() {
    return 'Old system response';
  }
}

class Adapter {
  constructor() {
    this.oldSystem = new OldSystem();
  }

  request() {
    return this.oldSystem.specificRequest();
  }
}

const adapter = new Adapter();
console.log(adapter.request()); // Old system response
Can you name the main structural patterns in… - sobes.tech