Interface segregation principle (ISP) – SOLID

Imagine that you are implementing an interface of a class pets, and the compiler complains about the non-inclusion of bark method in your Cat class; strange, isn't it?

ISP suggests any interface of a class should not force the clients to include any unrequired methods by that client; in our example, Cat does not need to implement bark method, and it is exclusive to Dog class:

The preceding diagram depicts ISP violation and how to get rid of the same by splitting the <<IPets>> interface to represent the Cat and Dog interface explicitly.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset