I - Interface Segregation (ISP)

About

A class should not implement interfaces that it won't use.

circle-info

Create interfaces based only on what the client needs, avoiding dependencies on things it won't use.

circle-check
Drawing

Example

In this example, the Exec class, which is the class that uses the method, specifies what it wants from ClassA.

So now, Exec don't know ClassA anymore, it only knows Interface2. And if ClassA changes in the future, Exec won't need to be re-compiled (Since there is no more import A from '.../ClassA').

Last updated