chapter three

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

 

This chapter covers

  • Applying the foundational principles of sound structure, from Separation of Concerns to SOLID.
  • Identifying "code smells" like low cohesion and tight coupling using simple analogies.
  • Refactoring a single large method into clean, maintainable classes using the 5-step Architectural Thinking Process and the Single Responsibility Principle.
  • Learning from our Hydra case study on taming a complex, duplicated system.
  • Discovering the surprising origins of the ideas behind modern object-oriented design.

3.1 Introduction

In Chapter 2, we filled our architect's toolkit with the processes for making and defending decisions. We learned how to identify constraints, use the '-ilities' to define quality, and capture our choices in ADRs.

Now that we know how to decide, it's time to learn what to build.

This chapter shifts our focus from the decision-making process to the fundamental principles that create quality code. We're moving from the "why" to the "what." Here, we learn the difference between code that simply works and code that lasts. The goal is to create code that is easy to maintain, easy to change, and resilient to the pressures of changing business goals.

3.2 Separation of Concerns

3.3 Cohesion and Coupling

3.3.1 Exercise: The "Simple Conversation" Test for Coupling

3.4 SOLID Principles

3.4.1 S – Single Responsibility Principle (SRP)

3.4.2 O - Open/Closed Principle (OCP)

3.4.3 L – Liskov Substitution Principle (LSP)

3.4.4 I – Interface Segregation Principle (ISP)

3.4.5 D – Dependency Inversion Principle (DIP)

3.4.6 Real-World Design Questions to Ask

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

3.5.1 The "Before" Code (The Monolithic Method)

3.5.2 The 5-Step Architectural Thinking Process in Action

3.5.3 The "After" Code (Separated Concerns)

3.5.4 The Payoff (The Defensible Decision)

3.6 Case Study: Taming the 35-Headed Hydra

3.6.1 The Scorecard Nightmare

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

3.7 Zooming Out: The Fractal Nature of Good Architecture

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

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

3.10 Checklist

3.11 Recap