Saltar al contenido
AKOS
Todos los packs
StableArquitecturadesign-patterns

Design Patterns

Operationalizes the classic Gang-of-Four pattern vocabulary as a shared naming system for recurring solutions — with heavy emphasis on when each pattern earns its complexity and when it's cargo-culted ceremony. Patterns are named solutions to *named problems*; using one without the problem present is the pack's central anti-pattern.

design-patternsgofcreationalstructuralbehavioralstrategy

Principios

  • · DP1 — Factory Method: trigger = object creation logic varies by subtype and callers shouldn't know which concrete class they get. Absent trigger → a plain constructor call is simpler.
  • · DP2 — Builder: trigger = constructing an object requires many optional parameters or a multi-step assembly process. Absent trigger → a plain constructor or object literal.
  • · DP3 — Singleton: trigger = exactly one instance must exist and be globally reachable (rare — usually a smell for hidden global state; prefer dependency injection of a single shared instance over a Singleton class).
  • · DP4 — Adapter: trigger = an existing interface doesn't match what a client expects, and you can't change either side. Absent trigger → just call the API directly.
  • · DP5 — Decorator: trigger = behavior needs to be added to individual objects dynamically, without subclassing every combination. Absent trigger → a single method/subclass is fine.

Patrones

  • · Name the problem before the pattern. If you can't state the pain in one plain sentence without naming a pattern, you don't have the trigger condition yet.
  • · Count real implementations. Strategy/Factory/Adapter all assume ≥2 real variants; with exactly one, skip the pattern and inline.
  • · Check the language first. Reaching for a Strategy class hierarchy in a language with first-class functions is usually one function parameter away from simpler.
  • · Pattern named in a PR description ≠ pattern actually needed. Review whether the trigger condition is present in the code, not just whether the pattern's shape is recognizable.
  • · Simplify before patterning. Often the "need" for a pattern is a symptom of a class doing too much (SRP) — fix that first; the pattern-shaped need sometimes disappears.

Riesgos

  • · Ver anti-patrones específicos del dominio en el pack.

Checklist

  • [ ] Every Strategy/Factory/Adapter pattern in the diff has ≥2 real implementations, not a hypothetical future one. (DP-E1)
  • [ ] No new global-state Singleton introduced; shared instances are dependency-injected. (DP-E2)
  • [ ] Pattern-named classes actually implement that pattern's structure. (DP-E5)
  • [ ] Language-native alternatives (closures, first-class functions) considered before a class-based pattern implementation. (DP-E3)
  • [ ] Decorator/Composite used only where dynamic composition or tree-uniformity is a real requirement. (DP-E4)
  • [ ] No layered creational-pattern stacking (Factory-of-Factories) without a matching real complexity.

Fuentes

En la bibliografía AKOS