Spis treści
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.
Advantages
- 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.
Disadvantages
- Many small interfaces.
- Greater effort during software development.
Examples
- 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
- 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
Sources
Main image
Materials
- Clean architecture — Robert C. Martin
- https://sii.pl/blog/solid-dobre-praktyki-programowania/
- https://javadeveloper.pl/solid/
- https://www.p-programowanie.pl/paradygmaty-programowania/zasady-solid/
- https://www.samouczekprogramisty.pl/solid-czyli-dobre-praktyki-w-programowaniu-obiektowym/
- https://pl.wikipedia.org/wiki/SOLID_(programowanie_obiektowe)
- https://en.wikipedia.org/wiki/SOLID
- https://en.wikipedia.org/wiki/Interface_segregation_principle
- http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod
- The Interface Segregation Principle – Robert C. Martin – https://drive.google.com/file/d/0BwhCYaYDn8EgOTViYjJhYzMtMzYxMC00MzFjLWJjMzYtOGJiMDc5N2JkYmJi/view
Sorry, there was a YouTube error.