Overview

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

This chapter shifts from deciding how to make architectural choices to understanding what good structure looks like in the code itself. It argues that software should be built to last: easy to read, easy to change, and resilient when business needs evolve. The central mindset is that code is read far more often than it is written, so maintainability is not a luxury but a core design goal.

The chapter explains that sound architecture begins with separation of concerns, then uses cohesion and coupling as practical ways to judge whether that goal is being met. High cohesion means a module, class, or interface has a focused purpose, while loose coupling means components depend on each other as little as possible. Through analogies like toolboxes versus junk drawers, LEGO bricks, and “simple conversations” instead of “interrogations,” the text shows how to spot design smells such as tangled responsibilities, hidden side effects, and workflow leaking into the wrong place.

From there, the chapter connects these ideas to the SOLID principles, showing how each one supports cleaner boundaries and smaller blast radius: single responsibility keeps one reason to change, open/closed encourages extension instead of risky modification, Liskov substitution demands trustworthy inheritance, interface segregation avoids bloated contracts, and dependency inversion moves dependencies onto abstractions. The later examples turn a monolithic order processor into smaller services and show how the same thinking scales up in a real case study involving a duplicated “Hydra” system, where composable parts replaced a costly mess. The big takeaway is that good architecture is fractal: the same principles that make a method clean also make a system durable.

Look to create toolboxes, not junk drawers!
Look to create toolboxes, not junk drawers!
Understanding High vs. Low Cohesion and Loose vs. Tight Coupling.
Understanding High vs. Low Cohesion and Loose vs. Tight Coupling.
The Midfielder should have one responsibility as a player, not also be coach and physio!
The Midfielder should have one responsibility as a player, not also be coach and physio!
The Open/Closed Principle (OCP). The player's core job is closed for modification, but their playbook is open for extension. In code, the playbook is the shared contract, and the new plays are the new Classes.
The Open/Closed Principle (OCP). The player's core job is closed for modification, but their playbook is open for extension. In code, the playbook is the shared contract, and the new plays are the new Classes.
Bob gets a red card for trying to play goalie when he is a midfielder after lying to the coach.
Bob gets a red card for trying to play goalie when he is a midfielder after lying to the coach.
Players should train only in the areas required for their position!
Players should train only in the areas required for their position!
Dependency Inversion Principle (DIP). By depending on the abstract contract (the playbook role) rather than the concrete Forward class (the specific person), the system becomes loosely coupled and easy to change.
Dependency Inversion Principle (DIP). By depending on the abstract contract (the playbook role) rather than the concrete Forward class (the specific person), the system becomes loosely coupled and easy to change.
Refactoring the OrderProcessor into multiple pieces maintains proper Separation of Concerns.
Refactoring the OrderProcessor into multiple pieces maintains proper Separation of Concerns.
Archie taking on and defeating the 35-headed Hydra!
Archie taking on and defeating the 35-headed Hydra!
Composability allows components to be assembled in various combinations.
Composability allows components to be assembled in various combinations.
The fractal nature of architecture on display.
The fractal nature of architecture on display.
Simula ushered in the dawn of Object-Oriented Programming concepts.
Simula ushered in the dawn of Object-Oriented Programming concepts.
Time to perform a structural audit on your code!
Time to perform a structural audit on your code!

Recap

  • Separation of Concerns is the foundation of good structure; it's the difference between a chaotic "junk drawer" and a well-organized "toolbox."
  • The goal is to create components with High Cohesion (where internal parts are strongly related) and Loose Coupling (where components connect like LEGOs, without depending on each other's internal details).
  • The SOLID principles are a "pre-flight checklist" for creating code that is easier to maintain, test, and change over time.
    • Single Responsibility: A class should have one reason to change.
    • Open/Closed: Extend behavior by adding new code, not modifying old code.
    • Liskov Substitution: Child classes must be true substitutes for their parent class.
    • Interface Segregation: Interfaces should be small and specific, not "fat."
    • Dependency Inversion: Depend on abstractions, not concrete details
  • Using abstractions and shared contracts (such as interfaces or abstract classes) is the primary way to build flexible systems that are open to extension and easy to test.
  • A key goal of good architecture is to minimize the "blast radius," ensuring that a change or failure in one area doesn't cause a catastrophic failure in another.
  • Great architecture isn't about one massive design decision, but the consistent application of these principles through many small, good decisions made daily.
  • Architectural principles are fractal. The same ideas apply from a single method up to the entire system.

FAQ

What is Separation of Concerns (SoC) in software architecture?

Separation of Concerns means each piece of code should do one thing and do it well. A module or class should have a single concern, such as handling validation, payment, or formatting, rather than mixing unrelated responsibilities together.

Why does a “junk drawer” codebase cause problems?

A “junk drawer” codebase mixes unrelated logic in one place, making it hard to find, change, test, and understand code. A small change in one area can accidentally affect unrelated behavior, increasing bugs and maintenance cost.

How do cohesion and coupling help measure code quality?

Cohesion measures how well the parts inside a module fit together. High cohesion means the module focuses on one purpose. Coupling measures how much modules depend on each other. Loose coupling is preferred because it reduces ripple effects when changes happen.

What is the difference between high cohesion and low cohesion?

High cohesion means a class or module contains closely related responsibilities that belong together, like a class that only calculates shipping costs. Low cohesion means the class mixes unrelated tasks, such as authentication, logging, and currency formatting in the same class.

What does tight coupling look like in code?

Tight coupling happens when one class depends heavily on another class’s internal details or sequence of calls. If changing one class forces many changes elsewhere, the code is tightly coupled and harder to maintain.

What is the “blast radius” in software?

The blast radius is how far a bug, failure, or change spreads through a system. A large blast radius means one change can break many parts of the application. Good architecture aims to keep the blast radius small.

What is the Single Responsibility Principle (SRP)?

SRP says a class should have only one reason to change. In practice, that means one class should focus on one responsibility, which improves cohesion, testability, and maintainability.

How does the Open/Closed Principle (OCP) improve design?

OCP says software entities should be open for extension but closed for modification. That means you should add new behavior by creating new classes or extending abstractions instead of constantly editing stable, working code.

Why is Dependency Inversion Principle (DIP) important?

DIP says high-level modules and low-level modules should both depend on abstractions, not concrete implementations. This makes the system easier to change, easier to test with mocks or fakes, and less tightly coupled.

What does the fractal nature of good architecture mean?

It means the same design principles apply at multiple scales: a method should have one job, a class should be cohesive, a component should be modular, and the whole system should be composed of well-separated parts. Good architecture repeats these principles consistently at every level.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


Close
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Grokking Software Architecture Grokking Software Architecture ebook for free
Close
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Grokking Software Architecture Grokking Software Architecture ebook for free