Software design and clean code

Stage 2 · Lesson 1 of 7

Single responsibility

SOLID with before and after code

The says a class should have one reason to change. A reason to change is a group of people or a kind of decision: pricing rules come from the business, the invoice layout from designers, the database from engineers.

An Invoice class that calculates, prints and saves itself changes for all three, so a layout tweak can break tax calculation. Split it, and each class stays small, focused and easy to test. is the related idea: the parts of a class should belong together. A useful test is to describe the class in one sentence without using "and".

Common trapreading it as "one method per class" and scattering code that always changes together across a dozen tiny classes.

A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock

Resources for this stage

Start with· follow one of these

  • CoursePaid
    Grokking SOLID Design Principles

    Design Gurus · Beginner · $50 one-time

    One chapter per principle, each with the violation and the refactoring that fixes it

  • CourseFree
    MIT 6.102: Software Construction

    MIT · Intermediate

    Free: the Specifications and Interfaces and Subtyping readings explain substitution as contracts

Keep handy

  • Search it for dependency injection and inversion of control: the articles that named the ideas

Also worth your time

Mark this stage as not done?