Interface Segregation Principle
Last updated
Last updated
Definition: Clients should not be forced to depend on methods they do not use.
Prefer Small cohesive interfaces to fat interfaces.
If there’s a class that implements a part of the interface, then the interface should be split into smaller interfaces that can be used separately.
Now let's see the problems introduced in this example:
The EmployeeService is a Read-Only Service which obviously doesn't need to implement the bloated ICRUDService interface.
The EmployeeService now violates LSP as there are methods that aren't implemented.
Now we separated the Read Interface from the Write Interface so service can be a Read-Only, a Write-Only, or even a Read/Write Service.