ISP — The Interface Segregation Principle
3 min readJan 23, 2022
The Interface Segregation Principle is a part of SOLID, a mnemonic acronym that bundles a total of 5 design principles.
It is often associated with clean code.
But what exactly is it, is it important to you, should you even care?
What does it state?
The Interface Segregation Principle (ISP) sets a pretty simple statement:
“No client should be forced to depend on methods it does not use.”
The ISP applied to the extreme will result in single-method interfaces, also called role interfaces.
You can take a look at the following example to get an idea of how the ISP can be violated in one way (it’s in TypeScript).
interface ReportService {
createEmployeeReport(employeeId: string): Report;
createCustomerReport(customerId: string): Report;
createManagementReport(projectId: string): Report;
}class EmployeeReportService implements ReportService {
createEmployeeReport(employeeId: string): Report {
return {
// ...
};
}
createCustomerReport(customerId: string): Report {
throw new Error("Method not implemented.");
}
createManagementReport(projectId: string): Report {
throw new Error("Method not implemented.");
}
}