Pinwheel, strategy, factory patrern

Design Patterns – Factory, Decorator, Bridge, Pinwheel

Design Patterns – Practical View

Factory, Abstract Factory, Decorator, Bridge, Pinwheel

This presentation focuses on why and where patterns are used in real systems. Not textbook definitions. Examples are from messaging / SMS / transactions.

Factory Pattern

  • Creates one object
  • Hides construction logic
  • Client does not know concrete class
Factory is about deferring object creation. Example: createSmsSender(type). Client code avoids new ProviderA(). Helps centralize construction rules.

Abstract Factory Pattern

  • Creates families of related objects
  • Factory of factories
  • Ensures compatibility
Abstract Factory is useful when multiple objects must be consistent. Example: SMS provider + credentials + formatter. You switch entire provider stack, not just one class.

Decorator Pattern

  • Adds behavior without inheritance
  • Wraps an object
  • Runtime composition
Decorator solves inheritance explosion. Example: Send SMS with retry + audit + metrics. Each decorator does one thing and wraps execution.

Bridge Pattern

  • Separates abstraction from implementation
  • Two dimensions evolve independently
Bridge is often confused with Strategy. Example: Message abstraction (SMS, Email) vs Transport (HTTP, SMPP). Both vary independently.

Aggregation vs Inheritance (Ice Example)

  • Inheritance: is-a
  • Aggregation: has-a
Bad inheritance: IceWithSalt extends Ice. Better aggregation: Ice has Additive (salt, lemon). Aggregation avoids rigid class hierarchies.

Click-to-View Systems (Composition)

  • Small focused objects
  • Wired together at runtime
  • Behavior assembled, not inherited
Modern systems prefer composition. Click-to-view means assemble behavior when needed. This leads to pinwheel-style designs.

Pinwheel Pattern – Concept

  • One stable core
  • Multiple independent spokes
  • Spokes can be added or removed
Pinwheel is not a GoF pattern. It is a composition style. Core does the main work, spokes add cross-cutting behavior.

Old Pinwheel Analogy

  • Center rod is fixed
  • Blades spin independently
  • Wind drives behavior
Think of execution as wind. Each blade reacts independently. No blade knows about others.

Pinwheel in SMS Example

  • Core: Send SMS
  • Spokes: Retry, Audit, Metrics
  • Strategy inside core
Core = actual provider call. Strategy selects provider. Decorators wrap execution. Abstract Factory creates provider stack.

Why Pinwheel Works Well

  • No if-else explosion
  • Explicit execution order
  • Easy per-client customization
Pinwheel is superior to AOP for per-transaction behavior. Debugging is easier. Behavior is visible and testable.