Phase 2 of 5  ·  Design & Modeling
Week 07 / 20   ·   Ch 7

Design
and Implementation

"Why clean code isn't enough — design matters"

📚 Ch 7 — Design & Implementation🧩 GoF Design Patterns♻️ Reuse Strategies⏱ ~20 min read

🔍Concept Deep Dives

Click each concept to expand — real examples, diagrams, pros & cons.

🧩

Design Patterns (GoF)

23 proven solutions to recurring OO design problems. Catalog by Gamma, Helm, Johnson, Vlissides (1994).

When to Use

Whenever you recognize a recurring structural or behavioral problem in your code.

Real-World Example

Observer = React state/events. Singleton = DB connection pool. Factory = framework object creation. Strategy = payment methods.

✓ Advantages

  • Proven solutions
  • Common vocabulary for teams
  • Reduce design effort

⚠ Watch Out

  • Can be over-applied (pattern fever)
  • Adds abstraction layers
  • Wrong pattern = worse code
Creational: Factory, Abstract Factory, Builder, Prototype, Singleton Structural: Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy Behavioral: Chain, Command, Iterator, Mediator, Memento, Observer, State, Strategy, Template, Visitor
🏗️

Object-Oriented Design

Design using classes, inheritance, polymorphism. Use UML to model before coding.

When to Use

Most modern application development in OO languages (Python, Java, C#, Ruby, TypeScript).

Real-World Example

Design: User→Account→Transaction class hierarchy before writing any Python/Java.

✓ Advantages

  • Encapsulation reduces complexity
  • Reusable abstractions
  • Maps to real-world concepts

⚠ Watch Out

  • Inheritance misuse (deep hierarchies)
  • OO not always the best fit (functional can be better)
Identify objects from use cases ↓ Design class structure + UML ↓ Define interfaces + operations ↓ Implement classes
♻️

Implementation Reuse

Use existing libraries, frameworks, components, and open-source instead of building from scratch.

When to Use

Always ask: does a library exist for this? Before building anything.

Real-World Example

Don't write your own crypto (use OpenSSL). Don't write your own auth (use Passport/Auth0). Don't reinvent logging (use Winston/Log4j).

✓ Advantages

  • Faster delivery
  • Battle-tested code
  • Reduced maintenance burden

⚠ Watch Out

  • Dependency hell
  • Security vulnerabilities in deps (Log4Shell)
  • License issues
Need: authentication Options: 1. Build from scratch (weeks, risky) 2. Use Passport.js (hours, proven) 3. Use Auth0 SaaS (minutes, managed) → Usually: option 2 or 3
🔧

Configuration Management

Managing changes to software components — version control, build management, release management.

When to Use

Always — from day 1. Even solo projects need version control.

Real-World Example

Git + GitHub + CI/CD pipeline is configuration management. Every PR is a controlled change.

✓ Advantages

  • Traceability of changes
  • Rollback capability
  • Team coordination

⚠ Watch Out

  • Overhead for very small teams
  • Merge conflicts
Version Control (Git) ↓ Build System (Gradle/npm) ↓ CI Pipeline (GitHub Actions) ↓ Release Management (tags/semver)

📋Quick Reference

θ Ch 7 Cheat Sheet — Design and Implementation
Observer Pattern
One-to-many dependency. Subject notifies all Observers when state changes. Used in: event systems, React state.
Strategy Pattern
Define a family of algorithms, encapsulate each, make them interchangeable. Used in: payment methods, sort algorithms.
Factory Pattern
Interface for creating objects, letting subclasses decide which class to instantiate. Hides creation logic.
Singleton
One instance only, global access point. Used for: DB connections, loggers. Controversial — hard to test.
Decorator
Add behavior to objects dynamically without subclassing. Used in: middleware, logging wrappers.
Facade
Simple interface to a complex subsystem. Used in: SDK wrappers, API clients.
Config Management
Version control + build management + change management. Git is your foundation.
θ
Sommerville's Key Points — Ch 7
Author's own summary from the end of the chapter.
  • 1Object-oriented design: design system using interacting objects, each managing its own state.
  • 2Design patterns: documented solutions to common design problems. GoF book has 23 patterns.
  • 3Patterns classified as: Creational, Structural, Behavioral.
  • 4Implementation reuse: open-source, libraries, frameworks, components.
  • 5Configuration management: version control, build management, change management, release.
  • 6Open-source development: use, modify, contribute. Understand licenses (MIT, GPL, Apache).

🧠Quiz — Test Yourself

Think through your answer first, then reveal.

Q1
Recall
Explain the Observer pattern with a real-world example.
Observer: Subject maintains a list of Observers and notifies them on state changes. Example: a stock price feed (Subject) notifies multiple display widgets (Observers) when the price changes. In code: React's useState + useEffect, or Node.js EventEmitter.
Q2
Apply
What is the risk of using too many design patterns?
'Pattern fever' — over-engineering simple solutions. A Singleton where a module-level variable would do. A Factory where a constructor would do. Patterns are solutions to RECURRING problems — if the problem isn't recurring, you don't need the pattern.
Q3
Analyze
Name 3 open-source license types and their key constraint.
MIT: do anything, keep copyright notice. GPL: derivative works must also be GPL (copyleft). Apache 2.0: do anything, keep copyright + patent notice, no trademark use. BSD: similar to MIT with variations. Commercial use forbidden: AGPL requires sharing source even for SaaS.
Up Next → Week 08
Software Testing
Unit, Integration, System, Acceptance — explained with one real example
Continue → Week 08