Listing Vault SE322 · chapter 07 · Structural Design Patterns

Chapter 07 — Structural Design Patterns

How classes and objects are composed into larger structures: Adapter, Bridge, Composite, Decorator, Facade and Proxy — and the pairs that are easy to confuse.

07chapter
lists
total items
07

Structural Design Patterns

10 lists

The Structural Family 6

PatternOne-line intent
AdapterTranslate one interface into another a client expects
BridgeSeparate an abstraction from its implementation so both vary independently
CompositeRepresent part-whole hierarchies so leaves and composites look alike
DecoratorAttach responsibilities dynamically by wrapping an object
FacadeProvide a simpler entry point to a complex subsystem
ProxyControl access to another object through the same interface

Adapter — Key Points 4

  1. Object adapter uses composition; class adapter uses inheritance where supported
  2. Changes the interface, not the core responsibility
  3. Common at legacy and third-party boundaries
  4. A two-way adapter implements both interfaces so either side can use the object

Bridge — Key Points 4

  1. Prevents subclass explosion across two independent dimensions of change
  2. The abstraction delegates implementation-specific work to an implementor
  3. m abstractions × n implementations becomes m + n classes instead of m × n
  4. Refined abstractions extend one side without touching the other

Composite — Key Points 4

  1. Clients treat leaves and composites uniformly — no conditionals
  2. Recursive operations make tree processing simple
  3. Needs care with ownership, cycles and traversal policy
  4. Participants: Component, Leaf, Composite, Client

Composite — Transparent vs Safe 2

  1. Transparent — child management lives on the Component; uniform but leaves expose meaningless operations
  2. Safe — child management lives only on the Composite; type-safe but clients must check types

Decorator — Key Points 4

  1. The decorator shares the component's interface and holds a reference to it
  2. It adds behavior before, after or instead of forwarding
  3. Composes features without subclass explosion
  4. Order of wrapping can change behavior; many small wrappers complicate identity and debugging

Facade — Key Points 4

  1. Simplifies an existing interface without adding functionality
  2. Reduces client coupling but does not forbid direct subsystem access
  3. Often the natural entry point of a layer
  4. Risk: it grows into an all-knowing god object

Proxy — The Four Kinds 4 + 1

  1. Remote — represents an object in another address space
  2. Virtual — defers creating an expensive object until it is needed
  3. Protection — checks access rights before forwarding
  4. Caching — stores results of expensive calls
  5. Smart reference — adds reference counting, lazy loading or locking

Easily Confused Pairs 4

PairThe distinguishing question
Proxy vs DecoratorSame structure — Proxy controls access, Decorator adds responsibilities
Adapter vs BridgeAdapter is applied after the fact; Bridge is designed in up front
Facade vs AdapterFacade simplifies an interface; Adapter converts one interface to another
Composite vs DecoratorComposite composes many children; Decorator wraps exactly one component

Emphasized in This Course 3

The lecture's own summary table names these three as the structural patterns covered.

  1. Adapter
  2. Composite
  3. Facade