SOLID Design Principles: The Interface Segregation Principle

Nisanur Sakacı
Orion Innovation techClub
2 min readMar 8, 2022

I. Introduction

SOLID principles allow writing “clean code” in object-oriented programming. Solid principles enable faster editing of the developed project.

Solid principles require 5 basic rules.

· S stands for SRP (Single Responsibility Principle)

· O stands for OCP (Open Closed Principle)

· L stands for LSP (Liskov Substitution Principle)

· I stand for ISP (Interface Segregation Principle)

· D stands for DIP (Dependency Inversion Principle).

II. I: Interface Segregation Principle (ISP)

According to the Interface Segregation Principle, separate interfaces should be created for each task. There should not be different tasks in an interface. The Interface Segregation Principle is the Single Responsibility Principle applied to interfaces. There is no other difference.
More than one responsibilities can be added in an interface when the Interface Segregation Principle is not applied. Every class that inherits from the interface must expose the function/method/object written in the interface in the class. This causes the Dummy code.
If the interfaces are separated according to the area of responsibility, there will be no unnecessary code in the interface or class that will inherit.
An example is a restaurant business. It can be assumed that orders are placed online, by phone, and face-to-face. When orders can be received in this way, the payment will be in two ways: Online and face-to-face. The program is first created using a single interface.

When a single interface is used, there is more than one unused function in the inherited class. This causes unnecessary code to be written in the code. Instead of a single interface, it would be more accurate to write different interfaces according to their tasks.

Orders can be created after the interfaces are created.

--

--