Member-only story

SOLID — Interface Segregation Principle

Alex
4 min readDec 7, 2023

The Interface Segregation Principle explains that clients should not be forced to implement interfaces they do not use. Interfaces should be smaller and more compact to prevent clients becoming dependent on methods that are irrelevant.

An example being if we wanted to make an app to help us book a holiday abroad. We may only need certain features such as booking flights and finding a hotel. However, we wouldn’t really need features such as buying clothes or organising dog care for the week since they are not specifically related to booking a holiday abroad.

Examples of ISP violation

Overweight/Fat Interfaces

An overweight/fat interface contains too many methods, some of which may be unrelated and unnecessary. Implementing an interface such as this can lead to interfaces being forced to depend on methods they don’t need which can lead to bloated code and increased coupling.

What is an interface?

Interfaces are basically contracts which define properties, events and methods that classes or structs can implement.

When a class or struct implements an interface the item will be forced to implement the functionality that is defined in the interfaces. This enables the class to be used in a polymorphic…

--

--

No responses yet