Skip to the content.

Interface Segregation Principle

No client should be forced to depend on methods it does not use.

The violation

One fat interface for everyone who works in the shop:

interface BookshopStaff {
    String sell(Book book, Customer customer);
    void restock(Book book, int copies);
    BigDecimal dailyTakings();
}

class WeekendTemp implements BookshopStaff {
    public String sell(...) { ... }                       // the actual job
    public void restock(...) { /* not allowed to */ }     // forced stub
    public BigDecimal dailyTakings() { throw ...; }       // forced landmine
}

Every implementer stubs or throws the methods that aren’t theirs, every client that only needs selling still sees (and can call!) accounting methods, and a change to restock’s signature recompiles the till code.

The fix

Role-sized interfaces: Bookseller, StockManager, Accountant. ShopManager genuinely does all three and implements all three; WeekendTemp implements exactly the one that’s true.

Benefits

Example test

StaffRolesIspTest