Add code examples, and documentation

This commit is contained in:
Aaron Po
2026-08-12 00:03:32 -04:00
commit 77c16e69f6
79 changed files with 4458 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
[← Design patterns index](README.md)
# 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. |
---
[All patterns](README.md)