CMD Guide
HomeOO & Low-Level DesignDesign Patterns Overview

Summary (2)

Quick reference for structural patterns. A summary table alone cannot separate Adapter, Decorator, and Proxy — they often share the same wrapper shape. Use the three-question discriminator below before memorizing pros/cons.

Three-question discriminator (Adapter vs Decorator vs Proxy)

QuestionAdapterDecoratorProxy
Does the interface change?Yes — adaptee has a different API; adapter implements the targetNo — same interface as the wrapped objectNo — same interface as the real subject
Does every call always forward?Usually translates then forwards (one-to-one mapping)Yes — adds behavior and always delegatesNo — may short-circuit (cache, deny, lazy-load stub)
Primary intentReuse an existing class with the wrong interfaceAdd responsibilities dynamically without subclassingControl access / stand in for the real object

Interview one-liner: same diagram, different force — name the force, not the arrows.

For depth, prefer the individual structural pages (Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy) over this summary alone.

Pattern NameDistinctive FeatureApplicabilityAn ExampleProsCons
AdapterBridges incompatibilities between interfacesWhen you want to use an existing class whose interface is not compatible with the rest of the codePower adapter for different plug typesEnables interoperability of interfaces; reusableIncreases overall complexity of the code
CompositeRepresents part-whole hierarchies of objectsWhen you want to treat individual objects and compositions of objects uniformlyGraphic drawing editor handling shapes and groups of shapesSimplifies client code; easier management of objectsDesign can become overly generalized
ProxyProvides a placeholder for another object to control access to itLazy loading, logging, access control, smart referenceInternet proxy server controlling access to web contentControl object access; reduce cost of expensive operationsCan introduce a level of indirection; may impact performance
FlyweightMinimizes memory usage by sharing as much data as possible with similar objectsWhen dealing with large numbers of similar objects with little variation in stateCharacters in a word processorReduces memory usage; efficient data sharingComplexity; managing shared state
BridgeSeparates an object’s abstraction from its implementationWhen you want to avoid a permanent binding between an abstraction and its implementationDifferent UI platforms with different backend renderersAbstraction and implementation can vary independently; scalabilityIncreased complexity; conceptual overhead
DecoratorAdds responsibilities to objects dynamicallyWhen extending capabilities of a class in runtimeAdding scrolling to a text view dynamicallyMore flexible than subclassing; avoid feature-loaded classesCan lead to complex code structure; hard to debug
FacadeProvides a simplified interface to a complex subsystemWhen there's a complex system and you want to provide a simple interface to itHome theater control systemSimplifies interface; reduces dependencies on outside codeCan become a single point of failure; may limit flexibility

Pattern taxonomy recap

FamilyWhat it solvesCanonical patterns
CreationalHow objects are instantiated and who decides the concrete typeSingleton, Factory Method, Abstract Factory, Builder, Prototype
StructuralHow classes/objects are composed into larger structuresAdapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy
BehavioralHow objects communicate and how responsibilities are distributedObserver, Strategy, Command, State, Template Method, Iterator, Mediator, Memento, Chain of Responsibility, Visitor

Structural patterns: when to use

PatternUse whenSkip when
AdapterYou need to use an existing class with an incompatible interfaceYou own the target interface and can change it
BridgeAbstraction and implementation must vary independentlyThere is only one implementation and no planned variation
CompositeYou need to treat individual objects and compositions uniformlyThe hierarchy is shallow and uniform by nature
DecoratorAdd responsibilities dynamically without subclassingA simple helper method or AOP is sufficient
FacadeYou need a simplified interface to a complex subsystemThe subsystem is already simple or the facade hides too much
FlyweightMany objects share most of their stateObject count is low or extrinsic state management is complex
ProxyYou need controlled access, lazy loading, or a remote stand-inIndirection adds more confusion than value

Interview trap box

Self-check

  1. Interface change? Always forward? May skip? Apply to logging middleware vs PayPal SDK bridge vs virtual proxy image loader.
  2. When does Facade become a god object, and how do you know?
🤖 Don't fully get this? Learn it with Claude

Stuck on Summary (2)? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **Summary (2)** (OO & Low-Level Design) and want to truly understand it. Explain Summary (2) from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **Summary (2)** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **Summary (2)** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **Summary (2)** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes