SOLID PrinciplesInterface Segregation PrincipleMedium⏱️ ~2 min

ISP Structure: Fat Interface vs Segregated Interfaces

The key structural pattern in ISP is decomposing one large interface into multiple small interfaces based on client needs and behavioral cohesion.

Anti-Pattern: Fat Interface

«interface»
Worker
+ work(): void
+ eat(): void
+ sleep(): void
+ getSalary(): Money
+ attendMeeting(): void

Problem: A Robot worker cannot eat or sleep. A Contractor may not attend meetings or receive salary the same way. Each implementer is forced to handle irrelevant methods.

ISP Solution: Segregated Interfaces

«interface»
Workable
+ work(): void
«interface»
Feedable
+ eat(): void
«interface»
Payable
+ getSalary(): Money
«interface»
MeetingAttendee
+ attendMeeting(): void

Now HumanEmployee implements Workable, Feedable, Payable, and MeetingAttendee. Robot implements only Workable. Contractor implements Workable and Payable but not MeetingAttendee if contractors work remotely without meetings.

Key Relationships

Interface Composition: Classes implement multiple small interfaces instead of one large interface. This is expressed as multiple realization arrows (dashed lines with hollow triangles) from the class to each interface.

Client Dependencies: Clients depend only on the interface they need. A WorkScheduler depends on Workable, while PayrollSystem depends on Payable. Neither client is coupled to methods it does not call.

Interview Tip: When asked to refactor for ISP, identify distinct client types first. Each client type suggests one segregated interface.
💡 Key Takeaways
Fat interfaces force implementers to handle irrelevant methods
Segregate by client role: each interface serves one type of client
Classes can implement multiple small interfaces (interface composition)
Clients depend only on the interface slice they need
Use realization relationships (dashed arrows) from class to each interface
📌 Examples
1Worker interface split into Workable, Feedable, Payable
2Document interface split into Printable, Scannable, Faxable for multifunction printers
← Back to Interface Segregation Principle Overview