Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info

The Interface Segregation Principle (ISP) is another principle of the SOLID acronym, a set of five principles of object-oriented programming and design. The principles make it easier to develop software that is easy to manage and maintain, and also to understand.

Panel
panelIconId1f4a1
panelIcon:bulb:
panelIconText💡
bgColor#E3FCEF

The Interface Segregation Principle is a concept in object-oriented programming that can be explained with a simple analogy:

Imagine a multi-purpose remote control with buttons for operating a TV, a sound system, and a gaming console. Now, if you only have a TV, it's unnecessary and confusing to have buttons for the sound system and gaming console. This remote would be much easier to use if it only had the buttons needed for each specific device.

In programming, the Interface Segregation Principle suggests something similar:

  1. Specific Interfaces, Not General: Just like having a remote control tailored for each device, this principle states that classes should not be forced to implement interfaces they do not use. Instead of one big interface, you should have several specific ones.

  2. Smaller, Customized Interfaces: Create small, specific interfaces that are tailored for each class, rather than one large, general-purpose interface. This way, a class will only have to implement methods that are relevant to it.

  3. Avoiding Unnecessary Implementation: It's like not having to put buttons for a gaming console on a remote control meant only for a TV. In programming, a class shouldn't have to implement functions that it doesn't need.

  4. Flexibility and Cohesion: This approach leads to a more flexible and cohesive code structure. It allows you to change and adapt parts of your system without affecting those that don't rely on those interfaces.

So, in simple terms, the Interface Segregation Principle advises that it's better to have several smaller, more specific interfaces than one large, catch-all interface. This makes your code more modular, easier to understand, and avoids unnecessary dependencies.

...

The Interface Segregation Principle states that clients should not be forced to depend on interfaces they do not use. In other words, it's about making fine-grained interfaces that are client-specific rather than having a single general-purpose interface.

...