liveBook · Manning

Chapter 3: The Principles of Sound Structure: From Code That Works to Code That Lasts

What you will learn in chapter 3 of Grokking Software Architecture

This chapter introduction previews the structural principles, code smells, refactoring example, and case studies covered later.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This chapter introduction previews the structural principles, code smells, refactoring example, and case studies covered later.

Introduction

This introduction frames lasting code as code designed for future readers, rather than merely for immediate functionality.

Key terms: Maintainability, code that lasts

3.2 Separation of Concerns

This section explains how giving each piece of code one focused job makes unrelated parts of an application less likely to interfere with one another.

Key terms: Separation of Concerns (SoC), concern, database logic, UI logic, business rules, ONE job, more focused methods

3.3 Cohesion and Coupling

This section uses cohesion and coupling to assess separation of concerns, then shows how avoiding hidden state changes can help preserve a sound structure.

Key terms: Cohesion, High Cohesion, Low Cohesion, Coupling, Loose Coupling, Tight Coupling, Pure Functions, Immutability, side effects, mutability

3.3.1 Exercise: The "Simple Conversation" Test for Coupling

This section teaches a code-reading test for tight coupling between two classes and explains why keeping a service’s workflow inside the service makes changes less disruptive.

Key terms: Client, Service, simple conversation, deep interrogation, tight coupling, blast radius, clear boundaries, dependencies, secret recipe, Encapsulation

3.4 SOLID Principles

Introduces SOLID as a flexible checklist for changeable code by refreshing four OOP concepts and explaining how an object refers to itself.

Key terms: Encapsulation, Abstraction, Inheritance, Polymorphism, this, self, self-reference, instance, SOLID principles, pre-flight checklist

3.4.1 S – Single Responsibility Principle (SRP)

This section explains how the Single Responsibility Principle keeps each class focused on one reason to change, and why that separation makes changes and tests less risky.

Key terms: Single Responsibility Principle, SRP, one reason to change, high cohesion, Player, fragile, Testability, High Cognitive Load, merge conflicts, TacticsEngine

3.4.2 O - Open/Closed Principle (OCP)

This section explains how the Open/Closed Principle lets developers add behavior without repeatedly changing stable code, and why that tradeoff improves a system over time.

Key terms: Open/Closed Principle, extension, modification, stable contracts, execute(), loose coupling, if/else, maintainability, reliability, blast radius

3.4.3 L – Liskov Substitution Principle (LSP)

Explains Liskov Substitution Principle as a behavioral promise, shows the cost of breaking it, and offers ways to recognize and test that promise.

Key terms: Liskov Substitution Principle, LSP, behavioral substitute, parent class, child class, deceptive inheritance, polymorphism, Reliability, Maintainability, blast radius

3.4.4 I – Interface Segregation Principle (ISP)

Explains why role-focused interfaces prevent classes from making promises they cannot fulfill and how splitting a bloated interface improves clarity and reliability.

Key terms: Interface Segregation Principle, fat interfaces, high cohesion, loose coupling, interface bloat, useless methods, Midfielder, practiceDivingSaves, maintainability, reliability

3.4.5 D – Dependency Inversion Principle (DIP)

This section explains how Dependency Inversion replaces direct reliance on concrete classes with shared contracts, improving testability and changeability when the tradeoff is worthwhile.

Key terms: Dependency Inversion Principle, DIP, high-level modules, low-level modules, abstractions, shared contracts, tight coupling, testability, maintainability, mock

3.4.6 Real-World Design Questions to Ask

Provides practical questions for spotting where code needs flexibility, clarity, separation, and reliable contracts during design.

Key terms: flexibility, clarity, maintainability, assumptions, tight coupling, separation, unit test, clear boundaries, extended, existing logic

3.5 In Action: “Before vs. After” SRP Refactor

Introduces an upcoming SRP refactor of order-processing code that appears sound on the surface but may hide architectural flaws.

3.5.1 The "Before" Code (The Monolithic Method)

This section defines a monolithic application and uses an all-in-one order-processing method to illustrate how combining distinct jobs can make code harder to change and riskier to test.

Key terms: monolith, single, unified unit, self-contained package, OrderProcessor, micro-monolith, all-in-one

3.5.2 The 5-Step Architectural Thinking Process in Action

This section applies a five-step architectural thinking process to turn a crowded OrderProcessor method into a defensible refactoring decision.

Key terms: Spark, Inquiry, ADR, Maintainability, Testability, OrderProcessor, Sketch, Validator, Payment, Inventory

3.5.3 The "After" Code (Separated Concerns)

The refactored design gives individual service classes focused jobs and uses an OrderService to coordinate their work.

Key terms: single responsibility, individual service classes, high-level OrderService, workflow

3.5.4 The Payoff (The Defensible Decision)

This section explains why separating the refactored code into focused classes is a defensible tradeoff and offers a practical way to make the refactor safer.

Key terms: defensible decision, maintainability, testability, blast radius, high cohesion, Extract Method, Move to New File

3.6 Case Study: Taming the 35-Headed Hydra

The section recalls the constraints behind the bank’s credit scorecard rewrite and introduces a case study of how structural principles were used during the rebuild.

3.6.1 The Scorecard Nightmare

This section shows how repeated sections across 35 industry scorecards made even small changes slow and risky.

Key terms: scorecard, Cash Flow Analysis, duplicated code, inconsistent scoring

3.6.2 The Clarity Engineer's Diagnosis: The High Cost of Duplication

Diagnoses the business cost of duplicated scorecards and shows how reusable, composable components made changes faster and more reliable.

Key terms: Separation of Concerns, technical debt, Maintainability, Reliability, Total Cost of Ownership (TCO), Composability, high cohesion, loose coupling, standardized contracts, CashFlowAnalysisComponent

3.7 Zooming Out: The Fractal Nature of Good Architecture

This section shows how separation of concerns applies from individual methods to whole applications, and why consistent small design decisions add up to sound architecture.

Key terms: Separation of Concerns, Single Responsibility Principle, High Cohesion, fractal, single responsibility, cohesive, loosely coupled, sound principles

3.8 The Dork Side: The First "Virtual Reality" - The Real Story Behind OOP

This section uses Simula’s origins to show how object-oriented design helps software accommodate changing, complex systems.

Key terms: Simula, objects, Separation of Concerns, classes, inheritance, virtual methods, TreatmentRoom, Open/Closed Principle, polymorphism

3.9 Your “In-Action” Mission: Perform a Structural Audit

This section teaches a comment-only audit for spotting unrelated responsibilities in existing code, with AI as an optional second set of eyes.

Key terms: structural audit, Clarity Check, low cohesion, seams, distinct responsibilities, second set of eyes

3.10 Checklist

This checklist asks readers to recall the chapter’s structural design concepts without explaining them.

3.11 Recap

The recap connects separation of concerns, SOLID principles, and small structural decisions to code that is easier to change without widespread effects.

Key terms: Separation of Concerns, High Cohesion, Loose Coupling, SOLID, Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion, blast radius

Where this is used later

Concepts explained in this chapter

← Chapter 2: The Architect's Toolkit: A Guide to Defensible Decisions Chapter 4: Thinking in Layers: Separating the 'How' from the 'Why' at Scale →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.