Software Engineering Architecture Lab

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

  1. Patterns Are Answers to Recurring Pain — How to read a pattern: problem, forces, solution, consequences.
  2. Strategy: Pluggable Payment Methods — Replace a growing if/else over payment types with interchangeable processors.
  3. Factory Method & Abstract Factory: Creating the Right Thing — Centralise the decision of which implementation to create.
  4. Builder, and Why Singleton Is Usually a Trap — Readable construction of complex objects — and global state disguised as a pattern.
  5. Adapter: Taming Third-Party Payment Gateways — Make Stripe-like and Razorpay-like SDKs look like your own interface.
  6. Decorator: Adding Behaviour Without Touching the Core — Wrap a processor with logging, retries, metrics and fraud checks.
  7. Facade & Proxy: Simple Front Doors and Smart Stand-ins — Hide subsystem complexity; control access with caching, lazy loading and security proxies.
  8. Observer: Reacting to Order Events — Let email, analytics and loyalty react to “order placed” without the order knowing them.
  9. Command: Refunds, Retries and Queued Work as Objects — Turn requests into objects you can queue, log, retry and undo.
  10. State: An Order Lifecycle Without the Giant Switch — Model PLACED → PAID → SHIPPED → DELIVERED with objects that know their own transitions.
  11. Template Method: One Checkout Skeleton, Many Variations — Fix the algorithm’s steps, let subclasses fill the variable parts.
  12. Chain of Responsibility: Validation & Fraud Pipelines — Pass a request through a line of independent handlers.
  13. 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

Other levels