SOLID: Interface Segregation Principle

Get introduced to the Interface Segregation Principle.

Introduction

The Interface Segregation Principle (ISP) is a design principle that does not recommend having methods that an interface would not use and require. Therefore, it goes against having fat interfaces in classes and prefers having small interfaces with a group of methods, each serving a particular purpose.

The goal behind implementing the ISP is to have a precise code design that follows the correct abstraction guidelines and tends to be more flexible, which would help in making it more robust and reusable. This becomes key when more and more features are added to the software, making it bloated and harder to maintain.

Example

Let’s construct a simple interface called Shape that has the area() method, and Square and Rectangle as the classes to implement it as shown below:

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.