Course contentsShow
← Computer Science
Lesson 2283 of 2,87251. Design PatternsFree lesson

Structural Pattern Trade-offs

Analyze the performance, complexity, and flexibility trade-offs when choosing between structural patterns.

Structural Pattern Trade-offs

You'll learn: How to evaluate performance, complexity, and flexibility when selecting among structural design patterns.

Weighing Your Options

Each structural pattern solves a different problem, but choosing between them requires analyzing trade-offs. There's no "best" pattern—only the best fit for your specific constraints.

Performance Considerations

Adapter and Facade add minimal runtime overhead—they're thin wrappers that delegate calls. Decorator chains can accumulate overhead when multiple decorators stack; each layer adds an indirection. Proxy may introduce latency (network proxies) or improve performance (caching proxies). Flyweight trades initial object-creation cost for memory savings but adds complexity in managing shared state.

Bridge separates abstraction from implementation, adding one extra layer of indirection but preventing combinatorial explosion of classes.

Complexity Trade-offs

Composite makes client code beautifully simple (treat individual objects and groups identically) but increases structural complexity with recursive hierarchies. Decorator offers extreme flexibility at the cost of harder debugging—stacked decorators obscure the core object. Facade reduces complexity for clients but can become a "god object" if not carefully bounded.

Flyweight requires careful analysis to separate intrinsic vs extrinsic state, adding cognitive overhead.

Flexibility Analysis

Decorator wins for runtime extensibility—add behaviors dynamically without inheritance. Bridge excels when both abstractions and implementations need independent evolution. Adapter provides flexibility to integrate third-party code without modification. Proxy enables cross-cutting concerns (logging, security) without touching business logic.

The inflexible option? Deeply nested Composite structures or overused Flyweight can lock you into rigid sharing schemes.

The Decision Framework

Choose based on your primary constraint:

  • Memory-constrained? Consider Flyweight
  • Simplifying complex subsystems? Use Facade
  • Need runtime behavior composition? Pick Decorator
  • Integrating incompatible interfaces? Use Adapter

Key Takeaway: Structural pattern selection requires balancing performance overhead, implementation complexity, and future flexibility—optimize for your specific bottleneck, not theoretical purity.