Senior
Tell me about the Interface Segregation principle (ISP) from SOLID.
sobes.tech AI
Answer from AI
The Interface Segregation Principle (ISP) from SOLID states that it is better to create several specialized interfaces rather than one universal interface. Clients should not depend on methods they do not use.
This helps avoid "fat" interfaces and reduces coupling in the code.
For example, instead of one interface:
interface Worker {
void work();
void eat();
}
it is better to split into two:
interface Workable {
void work();
}
interface Eatable {
void eat();
}
Then, a class that only works implements Workable and is not obliged to implement methods related to eating.
This improves code readability, maintainability, and testability.