·
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:
public interface Vehicle { public void drive(); public void stop(); public void openDoors(); } public class Bike implements Vehicle { // Can be implemented public void drive() {...} public void stop() {...} // Can not be implemented public void openDoors() {...} }
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.