| Lesson 4 | What makes up a design pattern? |
| Objective | List and apply the four essential elements of a design pattern: Name, Problem, Solution, Consequences. |
Names aren’t perfectly fixed-e.g., Abstract Factory has appeared as “Kit”-but de facto conventions let teams communicate precisely. Saying “use Factory Method here” is far more compact than re-explaining creation decoupling each time.
Example. In Java’s crypto API, the call below selects and returns a configured cipher without the caller knowing the concrete class-this is idiomatic Factory Method:
Cipher c = Cipher.getInstance("AES/GCM/NoPadding"); // Factory Method creates the right implementation
Naming precision. Prefer the specific GoF names: Factory Method (single-object creation hook) and Abstract Factory (families of related objects). Avoid the vague phrase “Factory Pattern.”
Modular systems evolve. Patterns give you names for the recurring forces (where variation lives) and structures that control that variation without hard-wiring it into inheritance trees or call sites. For example, Abstract Factory supplies entire families of related products (e.g., UI widgets for a theme), while Factory Method defers the choice of a single product to subclasses or injected creators.
Patterns are often grouped by intent: Creational (object creation variability), Structural (object composition and API shape), Behavioral (responsibility and communication). Use the category as a guide, not a rule.
You don’t do formal Big-O on patterns the way you do on algorithms, because patterns leave many details unspecified. Still, you can reason about typical trade-offs: e.g., Decorator may add indirection cost; Flyweight can reduce memory at the expense of coordination overhead.