The Gang of Four catalog names 23 recurring object-oriented design problems and the collaborations that address them. A pattern communicates intent and consequences. It is not a ready-made class diagram. Strategy says that an algorithm varies behind a stable contract, while Observer says that an unknown set of dependents receives notifications. The name is useful only when that pressure exists in the code.

The catalog groups patterns by what varies. Creational patterns move construction decisions, structural patterns compose objects and interfaces, and behavioral patterns assign work or communication. The categories help with recall, but intent decides the pattern.

Choose a Pattern by Intent and Cost

Start from the pressure in the code. Introduce the smallest pattern that makes a real variation or responsibility boundary explicit, then keep the condition that would justify deleting it.

PressureCandidateWhat it buysWhat it costsReject it when
Construction selects among related product familiesSoftware Architecture/Patterns/Design Patterns/Creational/Abstract FactoryKeeps compatible products and construction policy togetherFactory interfaces multiply with product familiesThere is one concrete family
Construction has many ordered or optional inputsSoftware Architecture/Patterns/Design Patterns/Creational/BuilderNames construction steps and protects invariantsExtra builder type and duplicated API surfaceA constructor or options record stays readable
Existing interface does not match a consumerSoftware Architecture/Patterns/Design Patterns/Structural/AdapterLocalizes translation at one boundaryAnother abstraction to test and maintainBoth sides are controlled and their contracts can be aligned directly
Add behavior around one object without subclass combinationsSoftware Architecture/Patterns/Design Patterns/Structural/DecoratorComposes responsibilities at runtimeNested wrappers obscure execution orderOne direct implementation has no meaningful variants
Choose one interchangeable algorithmSoftware Architecture/Patterns/Design Patterns/Behavioral/StrategyMakes policy selection explicit and testableMore types or delegatesA small conditional is stable and clearer
Notify unknown dependents about state changesSoftware Architecture/Patterns/Design Patterns/Behavioral/ObserverDecouples publisher from subscriber setOrdering, lifetime, and error handling become indirectThere is one required caller that should invoke directly
Encapsulate a request for queuing, undo, or dispatchSoftware Architecture/Patterns/Design Patterns/Behavioral/CommandTurns an operation into data with explicit executionBoilerplate around simple method callsNo delayed, logged, retried, or reversible execution exists

Similar structure does not imply the same pattern. Proxy and Decorator both wrap an interface, but Proxy controls access while Decorator adds responsibility. State and Strategy both delegate behavior. State changes from inside the context, while a client selects a Strategy as policy. If the variation disappears, collapse the abstraction.

Questions

References

4 items under this folder.