SOLID principle – ISP

This article introduces one of solid principles which is ISP (Interface Segregation Principle).

It is better to build a small-sized interface than a heavy interface as a small-size interface is easier to refactor and decouple.

Too many is better than too few

For example, you have IAnimal interface which has three methods(eat, move and sleep)

The above IAnimal interface works on most animals such as bear, elephant and tiger, etc. However, if you want plant class to implement IAnimal interface, you will notice that most behaviors of IAnimal interface does not work on plant.

However, if we can break IAnimal interface into three small interfaces (eat, sleep, move). Plant can’t move and sleep, but it can eat as it can consume energy and release oxygen. Hence, eat behavior can work on Plant interface

The above example proves that a small interface is more useful than a large interface.