Return to site

SOLID PRINCIPLES: Interface Segregation 🪓

· devops,java,solid,coding

SOLID principles basically form the fundamental guidelines for building 

👉 object-oriented , 

👉 loosely coupled , 

👉 robust, maintainable and 

👉 easily understandable applications .

 

No one should be required to implement methods in their classes which they will not use.

Larger interfaces should be split into smaller ones.

This ensures that implementing classes only need to be concerned about the methods that are useful to them.

This gives us flexibility to use only the required functionality. 

 

For ex:

 

 

For a bike class to implement openDoors method does not make sense. This should be fixed by breaking the Vehicle interface to multiple smaller interfaces with likely functionality so as no class is forced to implement non required methods.