1

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? Is it because in this case the interface is supposed to be fat by design? By SOA decree?

Are there other situations where the ISP is not a good idea?

Thanks in advance.

Dave Schweisguth
  • 36,475
  • 10
  • 98
  • 121
mnrtyrpt123
  • 143
  • 2
  • 10

3 Answers3

1

SOLID are good principle, my idea is that you shouldn't apply them when you think you're over-engineering ! For instance I apply ISP mainly on the classes of my Service Layer, in the business layer, I'll change my classes because it's a change in business, I won't create a new implementation (and I break the Open/Close principle, but I don't care because it's business changes !).

EDIT : I also apply ISP in my Data Layer, so I fact I apply ISP mainly for all the I/O matters (xml, sql, email ...).

If you apply ISP every where, you'll end up with hundreds of interface, and that could be a nightmare to debug / initialize.

remi bourgarel
  • 9,231
  • 4
  • 40
  • 73
0

A good time to not apply the ISP is when you've started with small interfaces and over time you learn more about the domain and discover that some of them are coupled. Those that are coupled can be refactored into fewer interfaces because you can see from real world usages (Rule Of Three) that they belong together - their behaviour is related; they are used in the same contexts and scenarios. It's with this experience of related interfaces that an informed decision can be made to collapse them. Then your domain becomes richer and you're not being DRY too early.

Problem with the above advice is that you are in fact applying ISP by starting with small and moving to big later. Perhaps the question is moot? :p

Matt Kocaj
  • 11,278
  • 6
  • 51
  • 79
-3

I do not use interfaces if I do not have more than 1 implementation. When the time comes the I apply the principle. The whole idea about interfaces is to have multiple implementations. Good luck.

mynkow
  • 4,408
  • 4
  • 38
  • 65
  • The idea about interface is to speak with an interface without knowing its implementations ! Interface is not a tool that enable you to apply a function to different implementation, it's a way of developing when you don't want to have dependence between all your classes and in both ways. – remi bourgarel Dec 08 '11 at 08:20
  • -1 Interfaces do not have 1-1 mapping to classes. imho interfaces should solve a smaller and more specific problem than a class. `IEnumerable` is a perfect example. – jgauffin Dec 08 '11 at 08:44
  • @remi why you want to stay behind the interface when you are 100% sure that there is ONLY ONE implementation? What is the benefit of introducing an interface and adding additional noise? – mynkow Dec 08 '11 at 13:04
  • @jgauffin Did I say that interface:class = 1:1? Where? – mynkow Dec 08 '11 at 13:07
  • @mynkow: your problem here is that you're not deciding how your business will change, it's your boss,your partners,your customer,whoever you can't know that you won't need another implementation,because your are not Nostradamus.Example : you have a class that'll send a mail to all of your customer.Tomorrow you also have to send it to some customers from a excel sheet. What do you do?you create 2 new class implementing ICustomerDataSource : MultipleCustomerDataSource and ExcelCustomerDataSource (SQLCustomerDataSource already exists and is injected into your mail class)? – remi bourgarel Dec 08 '11 at 13:22
  • I do not like how you think about these problems. I am 100% sure that you are in the pattern hole and you write more complex code than you should. You cannot create the perfect domain at the beginning. Your domain will become better and better and it will change often. When this happen you can introduce interfaces if it is necessary but not upfront. Go watch some screencasts of Eric Evans and read his book and stop trying to explain what are interfaces all about. – mynkow Dec 08 '11 at 18:10
  • @mynkow : that is a nice way to debate ("shut up and listen to these guy") :) Your response seems like you don't agree with SOLID principle, so I'm wondering why you're answering here. – remi bourgarel Dec 09 '11 at 16:40
  • Have you ever changed your domain or it is perfect from the beginning? Do you write interfaces for each class you write? – mynkow Dec 12 '11 at 18:01
  • no I don't, as I said in my answer, but I do it for the data/service layer. And I'd said that a domain rarely change, you add specification, you don't change the existing ones. – remi bourgarel Dec 19 '11 at 12:08