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
4
votes
2 answers

Interface Segregation in Qt

I always try to apply the S.O.L.I.D principles and I really like the Qt toolkit but I find myself stuggeling all the time with the single inheritance rule. If you are using multiple inheritance, moc assumes that the first inherited class is a…
TimW
  • 8,351
  • 1
  • 29
  • 33
3
votes
1 answer

Interface Implementation (Interface Segregation Principle)

I've a situation where I need to call a third party service to fetch some information. Those service could be different for different clients. I've a authenticate function in my Interface as follows. interface IServiceProvider { bool…
tkl33
  • 313
  • 1
  • 2
  • 9
3
votes
1 answer

Liskov substitution principle VS Interface Segregation principle

I have some troubles with understanding these two principles. This is a bit long-read-question, so be patient. Lets assume that we have a class abstract class Shape { abstract void onDraw(); } and interface interface SideCountable { int…
3
votes
1 answer

Interface Segregation Principle - How to decide what to segregate?

I believe the question is self explanatory. I would rather put more focus on the example to support question. public interface IEnumerable { IEnumerator GetEnumerator(); } public interface ICollection : IEnumerable { void CopyTo(Array…
Nikhil Vartak
  • 5,002
  • 3
  • 26
  • 32
2
votes
1 answer

Applying correctly interface segregation principle in my UML diagram

Context: Object oriented programing student, learning SOLID principles and trying to apply them in my school project. Making a Indeed-like website to apply for jobs using Windows form and a web application. Have to use a design patter that consists…
2
votes
1 answer

Does Interface Segregation Principle apply to data structures?

Lets imagine that we have a large data structure (lets call it Configuration) and various client classes (lets call them Services). Each service needs just one or two fields from Configuration. If we inject the whole Configuration object to the…
2
votes
2 answers

How to achieve polymorphism with the Interface Segregation Principle?

My goal is to understand the Interface Segregation Principle and achieve polymorphism at the same time. My expected result: I can achieve polymorphism with the Interface Segregation Principle. My actual result: No I can't. I am forced to create…
2
votes
1 answer

Cannot understand "contradiction" in Robert Martin's ISP article

I read the Robert Martin's article about the Interface Segregation Principle here. At the end of the article, when solving a problem with ATM UI architecture he stated: Consider also that each different transaction that the ATM can perform is…
2
votes
1 answer

Simulate private interfaces in java 8

I'm having an issue regarding the simulation of public interfaces in java 8. I have this interface with this methods right now: public interface A { void method1(T t) throws someException; void method2(T t) throws someException; …
carlos
  • 63
  • 1
  • 1
  • 4
2
votes
1 answer

Interface Segregation Principle in jQuery

Anyone able to give a good illustration of how this works in jQuery? Specifically with regards to the answer from here. It sounds the same as Single Responsibility Principle (SRP) for OOP? How is it different?
bcm
  • 5,470
  • 10
  • 59
  • 92
2
votes
2 answers

Interface Segregation Principle and Convenience/Helper Methods

How does the Interface Segregation Principle apply to convenience/helper methods? For instance: I want to create an interface that represents business partners. The bare minimum that I would need would be a setter and a getter method that would…
2
votes
3 answers

Interface segregation principle usage

This situation happened to me many times and I have no idea how to solve it. Interface segregation principle was made to prevent situations, when some interface implementations don't use it's functionality - that's obvious. There is often situation…
MistyK
  • 6,055
  • 2
  • 42
  • 76
2
votes
3 answers

I want to follow the interface segregation principle but the class is closed. Is a wrapper the right way?

More than a few times I've found my self working with a class that is closed (I can't modify it) that I wish implemented a nice narrow interface particular to my needs. My client code is supposed to own the interface but I know of no mechanism to…
1
vote
2 answers

How can I segregate fat interface through implementing adaptern pattern?

Suppose I have a some fat interface, which cannot be changed. And also I have some client class which want to use only few methods from that fat interface. How can be implemented adapter pattern for this situation, to achieve Interface Segregation…
1
vote
3 answers

When does the Interface Segregation Principle not apply? SOA?

I am looking for examples of scenarios where the Interface Segregation Principle (from SOLID) shouldn't be used. The only one that I have seen mentioned (but not explained) is the case of the interface for a service in the context of SOA. But why?…