Level 4: Design Patterns
Recognise the recurring pain behind a design, and reach for the pattern that relieves it — or decide you do not need one. Based on Design Patterns.
Outcome: Recognise the recurring pain behind a design, and reach for the pattern that relieves it — or decide you do not need one.
Payments, refunds, subscriptions, order lifecycles and fraud checks. Each pattern is introduced through a real ShopFlow problem: bad code first, then why it hurts, then the pattern, then its cost.
The pressure on ShopFlow: The business adds a new payment method, discount or workflow every month.
Lessons in level 4
- Patterns Are Answers to Recurring Pain — How to read a pattern: problem, forces, solution, consequences.
- Strategy: Pluggable Payment Methods — Replace a growing if/else over payment types with interchangeable processors.
- Factory Method & Abstract Factory: Creating the Right Thing — Centralise the decision of which implementation to create.
- Builder, and Why Singleton Is Usually a Trap — Readable construction of complex objects — and global state disguised as a pattern.
- Adapter: Taming Third-Party Payment Gateways — Make Stripe-like and Razorpay-like SDKs look like your own interface.
- Decorator: Adding Behaviour Without Touching the Core — Wrap a processor with logging, retries, metrics and fraud checks.
- Facade & Proxy: Simple Front Doors and Smart Stand-ins — Hide subsystem complexity; control access with caching, lazy loading and security proxies.
- Observer: Reacting to Order Events — Let email, analytics and loyalty react to “order placed” without the order knowing them.
- Command: Refunds, Retries and Queued Work as Objects — Turn requests into objects you can queue, log, retry and undo.
- State: An Order Lifecycle Without the Giant Switch — Model PLACED → PAID → SHIPPED → DELIVERED with objects that know their own transitions.
- Template Method: One Checkout Skeleton, Many Variations — Fix the algorithm’s steps, let subclasses fill the variable parts.
- Chain of Responsibility: Validation & Fraud Pipelines — Pass a request through a line of independent handlers.
- Composite, Bridge, Mediator, Iterator & Prototype — The less common patterns — recognise them when you meet them.
Source books
- Design Patterns — Eric Freeman, Elisabeth Robson, Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides