Extensible Systems

SRP says a class should have one reason to change. OCP says the system should accept new behavior without editing the stable core.

The common failure mode is a god object: calculations, persistence, logging, and transport all trapped in one class. The fix is to split the responsibilities and let the orchestrator coordinate instead of owning every detail.

Minimal Notes

  • SRP keeps one actor per change reason.
  • OCP keeps the stable path closed and the extension path open.
  • Strategy, interface boundaries, and composition usually beat new conditionals.

Lab 1.1: Refactoring a God Object

Split OrderManager into PriceCalculator, InventoryRepository, and NotificationService. The engine checks that the core math no longer owns inventory SQL or SMTP concerns.

Responsibility Boundary Scanner

Exercise 1.1: Refactoring a God Object

Analyzer idle

Split price calculation, inventory writes, and notifications into isolated modules.

Architecture Signals
Price logicinside OrderManager
Inventory schemainside OrderManager
SMTP payloadinside OrderManager
Validation Trace
  1. Edit the code, then run the architecture check.

Lab 1.2: Killing the Conditional Ladder

Replace the region switch with a TaxStrategy abstraction, then add UKTaxStrategy without putting UK back into TaxProcessor.

Extension Point Validator

Exercise 1.2: Killing the Conditional Ladder

Analyzer idle

Add UK tax behavior through a strategy without editing TaxProcessor for UK-specific logic.

Architecture Signals
TaxProcessorswitch ladder grows per region
UK region tokenwould require core edit
Validation Trace
  1. Edit the code, then run the architecture check.