2. ISP: The Interface Segregation
Principle
The Interface Segregation Principle states that Clients should not be
forced to depend on methods they do not use.
Interfaces should belong to clients, not to libraries or hierarchies.
Following this principle makes you split fat interfaces into specific ones
that will only show methods that are required for the clients.
3. PROS AND CONS
WITH OUT ISP
In absence of ISP, you have
one Generic FAT interface
and many classes
implementing it. Assume that
you had 1 interface and 50
classes. If there is a change
in interface, all 50 classes
have to change their
implementation
WITH ISP
you will divide generic FAT
interface into small
interfaces. If there is a
change in small interface,
only the classes
implementing that interface
will be affected.
To make the code more
readable and manageable.
4. Interface Segregation Principle in
Real life
In terms of the violation of
the ISP, shows a big
dustbin for throwing all
kinds of garbage away
without any kind of
segregation.
5. Interface Segregation Principle in
Real life
With ISP, the following
image is a good example
of segregation in our real
life.
8. CONCLUSION
In simple words the principle is saying, do not design a big fat interface
that forces the client to implement a method that is not required by it,
instead design a small interface. So by doing this class only implement
the required set of interface(s).
If there is big fat interface then break it into a set of small interfaces with
the related method(s)