Interface segregation principle
Many small and dedicated interfaces are better than few and general.
The purpose of this rule is nonexistence interfaces, which do many things and has many responsibilities. Wrong projected interfaces have a tendency to grow up too much. They are becoming incoherent. Classes, which implement these interfaces are incoherent too, and they must do, what they do not need. They depend on the methods they do not use.
This rule can be applied to methods, functions, classes, modules and packages.
- Easier to ensure the Liskov substitution principle and the Single responsibility principle.
- Easier code maintenance.
- Greater code readability.
- Easier code change.
- No need to implement unnecessary methods in classes that should not implement them.
- No God-interfaces.
- The code is less dependent on another code.
- Many small interfaces.
- Greater effort during software development.
- Interface IAnimal had method Run. Classes Dog and Fish implement this interface. In class Fish method Run is unnecessary.
- Interface File has two methods: Read and Write. Class FileOnlyToRead implements this interface. Method Write in unnecessary or do something different what this method name informs us (it can not write because it is read-only file).
All posts from mini project: Learn SOLID and OOP principles:
- SOLID exercises
- S like Single responsibility principle
- SOLID exercises — Kata
- O as Open-closed principle
- L jak Liskov Substitution Principle
- Interface segregation principle
- KISS — Keep it simple, stupid
- DRY — Don’t repeat yourself
- Dependency inversion principle
- SLAP — Single Level of Abstraction Principle
- Composition Over Inheritance
- Encapsulate what changes
- Lod — Law of Demeter
- ES as Exercises of Single responsibility principle
- EO as Exercises of Open/closed principle
- EL as Exercises of Liskov Substitution Principle
- EI as Eexrcises of Interface segregation principle
- ES as Exercises of Dependency Inversion Principle
- Object-oriented programming
- OOP — Object-Oriented Programming — Advice
- OOP — Object Oriented Programming
- Clean architecture — Robert C. Martin
- The Interface Segregation Principle – Robert C. Martin – https://drive.google.com/file/d/0BwhCYaYDn8EgOTViYjJhYzMtMzYxMC00MzFjLWJjMzYtOGJiMDc5N2JkYmJi/view