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
GoF design patterns — three families
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)
Object-oriented design — from use cases to code
1Identify objectsPull candidate objects from the use cases.
2Design class structureModel relationships with UML.
3Define interfaces & operationsSpecify what each class exposes.
4Implement classesWrite the code from the design.
♻️

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
Reuse decision — need: authentication
1Build from scratch — weeks of work, risky
2Use Passport.js — hours, proven library
3Use Auth0 SaaS — minutes, fully managed
Usually pick option 2 or 3 — don't reinvent battle-tested infrastructure.
🔧

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
Configuration management — the change pipeline
1Version ControlGit — track every change.
2Build SystemGradle / npm — reproducible builds.
3CI PipelineGitHub Actions — test on every push.
4Release ManagementTags & semver — controlled releases.

📋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).

🌍From the Book & Beyond

📖

Case Study — The Wilderness Weather Station

Sommerville walks the whole OO design process using one running example: embedded software for a wilderness weather station that collects local weather data and beams it to a weather information system over a satellite link. You watch the design grow step by step — a context model (Figure 7.1), use cases like "Report weather" and "Powersave," subsystems (Fault manager, Data collection, Instruments) broadcasting over a shared communication link, object classes such as WeatherStation and WeatherData, a sequence diagram for data collection, and a state diagram of Shutdown → Running → Collecting. One tiny system, five design activities, fully worked.

2026 Perspective — Patterns Baked In, Open Source by Default

The Observer pattern Sommerville describes by hand? In 2026 you rarely write it yourself — it's baked into React state, RxJS streams, and Kotlin flows. Frameworks ship the Gang of Four patterns as defaults, so the real skill is recognizing which pattern your framework is handing you. And the chapter's open-source section became the whole industry: nearly every modern app sits on an open-source stack. That brought a new duty — supply-chain security. After incidents like log4shell and the 2024 xz backdoor attempt, teams now track dependencies with SBOMs and lockfiles. Reuse is free; trusting blindly isn't.

🧠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