Design Patterns: S.O.L.I.D. Interface Segregation Principle

Providing Focused Behaviors for Classes

As part of the S.O.L.I.D. design principles, the Interface Segregation Principle (ISP) supports other S.O.L.I.D. principles in providing classes with focused behavior by ensuring interfaces inherited by classes remain lean and focused on specific behaviors.

To illustrate ISP, I’ll use examples from the Single Responsibility Principle (SRP) article.

I’ll begin with the Employee class.

To use this class as a template for employee of different types (Supervisor), I’ll create a new interface for this class to inherit different types of behavior as needed.

However, I need to provide a new specific behavior for the Supervisor type of employees, so I’ll create a new interface to provide the ability to conduct performance reviews, which is then inherited by a new class, adding that new behavior.

To recap, I implemented behavior for employees using two interfaces, each with distinct behavior.

By keeping each interface with a narrow focus for behavior, I’m adhering to the ISP.