Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top