2.7 KiB
2.7 KiB
Cross-pattern comparisons worth memorizing
These are the distinctions most likely to be tested, and the ones that actually bite in review:
| Confusion | The tell |
|---|---|
| Bridge vs. State vs. Strategy | Near-identical UML (context → interface, delegate). Bridge: two hierarchies designed up front, both varying. State: the delegate swaps itself and drives transitions. Strategy: interchangeable, mutually-unaware algorithms chosen by the client. |
| Decorator vs. Proxy vs. Adapter | All wrap one object. Adapter changes the interface. Decorator keeps it and adds behavior, client-controlled and stackable. Proxy keeps it but controls access/lifetime and manages its own subject. |
| Decorator vs. Composite | Decorator has exactly one child and adds responsibility; Composite has many and aggregates their results. |
| Facade vs. Mediator | Direction. Facade is one-way and the subsystem doesn't know it exists. Mediator is many-way and colleagues hold references to it. |
| Mediator vs. Observer | Mediator removes mutual dependencies among a known set of components via a hub. Observer creates dynamic, independently-subscribable one-way links. Often combined: mediator-as-publisher. |
| Memento vs. Command | Not rivals — partners. Command = "the operation"; Memento = "the state to restore if it's undone." |
| Facade vs. Abstract Factory | Both hide a subsystem. Abstract Factory hides only creation; Facade hides creation and call sequencing. |