Software design and clean code

Stage 2 · Lesson 4 of 7

Interface segregation

SOLID with before and after code

The says clients should not depend on methods they do not use. A single Machine interface with print, scan and fax forces a basic printer to implement fax, usually by throwing an error, which also breaks Liskov substitution.

Splitting it into Printer, Scanner and Fax lets each class implement only what it really does, and lets each caller ask for only what it needs. Small interfaces also make tiny: a Printer needs one method. Design interfaces from the caller's side: what does this code need from its collaborator?

Common trapgoing the other way and splitting every interface into one-method pieces that no caller ever uses separately, which adds names without adding clarity.

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?