Files
freemo d9e5668cec fix(skills): comprehensive final audit pass for programming-patterns skill
Fixes and improvements from exhaustive audit:

Consistency fixes in SKILL.md:
- 'Pipe & Filter' → 'Pipe and Filter' (one stray '&' found and corrected)
- 'Singleton for factory instance' → clarified to 'register factory as
  singleton-scoped via DI container' (less misleading wording)
- Documentation Format section updated with note that SKILL.md itself is the
  authoritative source for related-pattern combinations

Coverage fix — Related Patterns sections:
- Added '## Related Patterns' to ALL 94 pattern files (was 0/94)
- Each section lists 3–6 related patterns with relationship descriptions
- Covers: why they're related, when to prefer one vs the other,
  and which are often confused

SOLID principles → Creational → Structural → Behavioral → Architectural →
Concurrency → Functional → Resilience → Data Access → Messaging →
Testing → Error Handling → Microservice — all 13 categories covered

Code verification:
- Python: 0 failures (all 85 testable blocks pass)
- Go: 0 failures (all 76 testable blocks pass)
- JavaScript: 0 failures (all 78 testable blocks pass)
- All 239 code blocks verified correct after edits

Final skill state:
- 108 files, 36,524 lines across 13 reference categories
- 94/94 pattern files have Related Patterns sections
- 2,815-line SKILL.md with 67 decision trees, 23 scenarios,
  0 broken references, 0 naming inconsistencies
2026-04-15 13:22:13 -04:00
..

Creational Design Patterns

Creational patterns deal with object creation mechanisms — abstracting instantiation so that systems remain flexible about what gets created, who creates it, and how.

The 7 Creational Patterns

Pattern Intent Complexity Frequency
Factory Method Defer instantiation to subclasses via a creator method Low Very High
Abstract Factory Create families of related objects without concrete classes Medium High
Builder Construct complex objects step-by-step with a fluent API Medium High
Prototype Clone existing objects instead of building from scratch Low Medium
Singleton Ensure exactly one instance exists globally Low High
Object Pool Reuse expensive objects from a pre-allocated pool Medium Medium
Dependency Injection Supply dependencies externally instead of creating them internally Low Very High

When to Use Which

Need to create one of several related types at runtime?
  --> Factory Method

Need to create families of related objects that must be consistent?
  --> Abstract Factory

Need to construct a complex object with many optional parts?
  --> Builder

Need to duplicate an existing configured object?
  --> Prototype

Need exactly one shared instance (and DI is not an option)?
  --> Singleton

Need to reuse expensive-to-create objects (connections, threads)?
  --> Object Pool

Need to decouple a class from the specific implementations it uses?
  --> Dependency Injection

Comparison Matrix

Concern Factory Abstract Factory Builder Prototype Singleton Object Pool DI
Hides concrete type Yes Yes Partially No N/A N/A Yes
Supports families No Yes No No No No Yes
Fluent API No No Yes No No No No
Avoids new Yes Yes Yes Yes No Yes Yes
Thread-safety concern Low Low Low Medium High High Low
Testability Good Good Good Good Poor Good Excellent

Key Principle

Favor composition over inheritance, and injection over creation.

Most modern codebases rely heavily on Factory Method and Dependency Injection as their primary creational strategies. Use others when their specific strengths match a concrete problem.

Language Idioms

  • Python: Factories are often plain functions; Singletons use __new__ or module-level instances; DI via constructor args.
  • Go: Factories are NewXxx() functions; Singletons use sync.Once; no classes so Builder uses method chaining on structs.
  • JavaScript: Module exports naturally singleton; Factories return plain objects or class instances; Prototype via Object.create or manual clone.