SOLID Design Principles: The Interface Segregation Principle

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.

--

--

--

Orion Innovation Turkey Technology

Recommended from Medium

Hey Coders!

DIGITAL TRANSFORMATION- SIMPLIFYING WORK

ServiceNow Partner, India-Service Stack Technologies

The New and Improved NIUPOT Lottery

Dynamic Programming, Part 2–1

Kotlin 1.4 Online Event Recap

What is Algorithm Complexity and Big O Notation? | Learn DSA

A Beginner’s Guide to CSS Flexbox

Easy email sending for your website

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nisanur Karatepe

Nisanur Karatepe

More from Medium

SOLID Design Principles: The Single Responsibility

Birth Control for Bugs: Test-Driven Development

Design Clean SOLID Architecture for Analytics

MVC Design Pattern