Card 05/ 05

RecapDifficulty: Advanced1 min

Recap: Choosing a Structural Pattern

Compare the interfaces on both sides of the wrapper, and count what it holds.

The seven structural patterns are told apart by a few questions about the object in the middle.

  • Does the interface change? A different interface over one object is Adapter; a simpler one over several is Facade.
  • If it is kept, why? Adding behaviour, in layers that stack, is Decorator; controlling when or whether a call happens is Proxy.
  • How many does it hold? Many children of its own interface, combined, is Composite; exactly one, added to, is Decorator.
  • When was the interface introduced? Designed in, so two hierarchies vary apart, is Bridge; added afterwards to fit an existing class is Adapter.
  • Is the object shared? One immutable object per key, used by many, is Flyweight.