In this example, these would be the three categories Cars, Ships, and Aircraft: At first glance, you can see how much of a problem the construction of this interface poses, since it requires the implementation of the , and methods. As we all know a car can only drive so in and method it throws exception with appropriate message, class works the same way as boat can swim and exception must be thrown for other methods too. For airplanes, both methods are reasonable since airplanes can fly both on landing gear and in the air, but for the method, the exception must be thrown.
Such code violates the interface segregation principle because interfaces are not specialized and force implementation of methods that not all classes require. This interface is too generic and contains too many implementation possibilities. So how do we change photo retouching the code so that it meets the interface isolation principle while allowing cars to drive, ships to swim, and planes to drive and fly? Each of these activities should be separated into a separate interface so that an implementation can choose which interface it implements based on the required activity. So, let's create three appropriate interfaces.

Interfaces designed in this way are specialized and have terms by which we can determine what exactly they are responsible for. We have organized the interfaces correctly and now it is enough for each vehicle to implement only the functionality it really needs. So let's look at the improved implementation of the , and classes: Thanks to the interface isolation principle, our code becomes shorter and simpler. Types are interchangeable, even when a base type is used, its derived type can be used without changing the behavior of the first type. This issue will become clearer after an example.
|