In software design the use of interfaces to give a level of abstraction can be very tricky.

Consider we have an interface that has many methods, and a set of classes implementing that interface. Now if we want to create a new class that is interested only in a few methods of that interface, we will have to implement all the interface methods, even the ones we wouldn’t want to put in the new class. Now, one may leave the undesired methods bodies empty and another may throw a method not implemented exception, and that will cause an inconsistent and unexpected behavior at runtime.

In software design, that interface is called polluted or fat interface; because it has too many methods that not all of its implementing classes would want to know about. See the following diagram:

Interface segregation principle has solved this issue by dividing the polluted interface into smaller ones, and each class will decide which interface to implement according to its needs. See the following diagram:

Leave a Reply

Your email address will not be published.

Captcha Time limit is exhausted. Please reload the CAPTCHA.