Questions tagged [interface-segregation-principle]

For questions about the Interface Segregation Principle (ISP) in object-oriented design, one of the SOLID principles enumerated by Robert C. Martin. It states that "clients should not be forced to depend upon interfaces that they do not use."

Robert Martin introduced the Interface Segregation Principle in 1996. It seeks to avoid coupling between different clients of an interface.

When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.

Martin proposed the pattern as a solution to achieve interface segregation.

By making use of the ADAPTER pattern, either through delegation (object form) or multiple inheritance (class form), fat interfaces can be segregated into abstract base classes that break the unwanted coupling between clients.

Martin later included the ISP as the fourth of his .

See the ISP article under Principles of OOD.

57 questions
75
votes
5 answers

In SOLID, what is the distinction between SRP and ISP? (Single Responsibility Principle and Interface Segregation Principle)

How does the SOLID "Interface Segregation Principle" differ from "Single Responsibility Principle"? The Wikipedia entry for SOLID says that ISP splits interfaces which are very large into smaller and more specific ones so that clients will only…
29
votes
3 answers

The difference between liskov substitution principle and interface segregation principle

Is there any core difference between Liskov Substitution Principle (LSP) and Interface Segregation Principle (ISP)? Ultimately, both are vouching for designing the interface with common functionalities and introduce a new interface when you have…
28
votes
3 answers

Is Interface segregation principle only a substitue for Single responsibility principle?

Is interface segregation principle only a substitue for single responsibility principle ? I think that if my class fulfill SRP there is no need to extract more than one interface. So ISP looks like solution in case we have to break SRP for some…
27
votes
7 answers

What is the reasoning behind the Interface Segregation Principle?

The Interface Segregation Principle (ISP) says that many client specific interfaces are better than one general purpose interface. Why is this important?
26
votes
6 answers

Interface Segregation Principle- Program to an interface

I was reading about SOLID and other design principles. I thought ISP was the same as "Program to an interface, not an implementation". But it looks like these are different principles? Is there a difference?
22
votes
9 answers

Design pattern for default implementation with empty methods

Is there a specific design pattern that describes the scenario where a non-abstract default implementation is provided that implements all or some of the methods on the interface with empty, NO-OP implementations. This being done with the intent of…
15
votes
2 answers

Can Interface Segregation Principle be applied to Python objects?

In an effort to apply SOLID principles to a Python project that has grown organically and is in need of re-factoring, I am trying to understand how the Interface Segregation Principle can be applied to the Python language, when Interfaces don't…
13
votes
4 answers

Is the Composite Pattern SOLID?

A Leaf in the Composite Pattern implements the Component interface, including Add, Remove, and GetChild methods that a Leaf is never going to use. This seems to be a violation of the Interface Segregation Principle. So is the usage of Composite…
7
votes
4 answers

Interface Segregation Principle and default methods in Java 8

As per the Interface Segregation Principle clients should not be forced to implement the unwanted methods of an interface ...and so we should define interfaces to have logical separation. But default methods introduced in Java 8 have provided the…
7
votes
2 answers

Inheritance and Interface segregation principle

Does inheritance from a class with unused methods violates the interface segregation principle? For example: abstract class Base { public void Receive(int n) { // . . . (some important work) OnMsg(n.ToString()); } …
astef
  • 8,575
  • 4
  • 56
  • 95
6
votes
6 answers

Interface segregation and single responsibility principle woes

I'm trying to follow the Interface Segregation and Single Responsibility principles however I'm getting confused as to how to bring it all together. Here I have an example of a few interfaces I have split up into smaller, more directed…
4
votes
1 answer

How do I implement the Interface Segregation Principle using smart pointers in C++?

I come from a Delphi and C# background so I understand interfaces from their perspectives. I have been doing C++ for a few years and still learning interfaces from its perspective. In my application I have a situation where I need classes that…
4
votes
2 answers

c# interface segregation principle example confusion

I'm fairly new to programming and i'm having trouble to understand how to apply effectively the principle showed in the following link (the ATM one): http://www.objectmentor.com/resources/articles/isp.pdf Basically it starts with a design that does…
4
votes
1 answer

Confusing use of Adapter pattern in java.awt.event package and violation of Interface Segregation Principle ( ISP )

The usage of Adapter patttern in the java.awt.event package looks confusing to me. On the first hand it seems a clear violation of Interface Segregation Principle ( ISP ). Like the MouseMotionAdapter class implements MouseMotionListener but provide…
aknon
  • 1,408
  • 3
  • 18
  • 29
4
votes
2 answers

Is interface-segregation principle about classes or objects?

To remind (from wiki): The interface-segregation principle (ISP) states that no client should be forced to depend on methods it does not use. And now look at my example. Here's my mutable entity. It is edited from somewhere and it is able to…
1
2 3 4