Part 2 of 6 · 1 min read
The idea
Callers should see only what they use.
Think of a TV remote with sixty buttons given to a guest who only needs volume and power. Every extra button is something to read past, and a place to press by accident. A remote with just the buttons that guest needs is simpler and safer.
The interface segregation principle says the same of code. A caller should depend only on the methods it uses. If an interface offers ten methods and a caller needs two, the other eight are noise, and also a risk.
CA explains the risk with a picture. A class OPS offers three operations, and three users each call just one. In Java, every user refers to OPS itself, so each one is tied to all three operations. If the second operation changes, the first user must be built and released again, although nothing it calls was touched.
The cure is to put each operation behind its own small interface. The first user then sees only its own interface, and edits to the other operations never reach it.
Interface segregation principle
The interface segregation principle says that a class should not be forced to depend on methods it does not use, so large interfaces are split into smaller ones by purpose.
Example: a Bookable interface with one method book, instead of one big RoomOperations interface.
Check yourself: 1. In CA's example, why must the first user be recompiled when the second operation changes? 2. How does splitting the interface prevent that? 3. What does a caller see after the split?