This is the fourth of five posts talking about the SOLID principles. This principles are a great guide to write good source code. Each post will talk about one of the principles:
- S Single responsability principle
- O Open/Closed principle
- L Liskov substitution principle
- I Interface segregation principle
- D Dependency inversion principle
Interface segregation principle
Its better to have many small interfaces, than a few big ones. Every code must only depend on the interfaces that directly needs and no more.
Imagine a Plane class that has some functionalities at its service: like flight control and comunications. Its better to segregate those functionalities into two separte interfaces than have only one.
It’s better to segreate complex interfaces into smaller ones: