-1

I have recently seen an example of what I think is a clear violation of ISP, but my colleague argued it is easier to use. This is what happened:

  1. We had Options class that had 2 fields sent as a parameter to one of the methods where both fields were in use.
  2. Then there was a new field added that was used in another method, but original method never needed it.

So that when you call a first method you have to send an option that has a field that is totally irrelevant for the method.

I have not seen applications of ISP to classes/requests, and not just interfaces itself, but I consider this as a part of the interface actually.

So I am wondering if this is a part of ISP or not.

  • By "one of the request" do you mean parameters to a controller that handles an HTTP request? – Greg Burghardt Jun 28 '18 at 11:36
  • Not really, I just meant a method of the interface, will fix. Sorry for the confusion, it is some request, but it is virtually non important for the sake of this question. – Ilya Chernomordik Jun 28 '18 at 13:43
1

IMHO for sure it is. Interface segregation principle talks about code having access to something it does not need and that normally leads to confusion and bad maintenance in the long run.

Your colleague is arguing about "it is easier to use" ... that smells a lot like starting a "God object" which is easy to use but a hell to maintain.

And in this specific case you can have an overloaded method with one more parameter and two different interfaces with proper names. That would make code cleaner in the long run.

For reference: https://en.wikipedia.org/wiki/Interface_segregation_principle

  • Yeah, he reconsidered :) – Ilya Chernomordik Jun 28 '18 at 10:49
  • I'm happy to hear that. Every time a programmer violates a SOLID principle a kitty dies. – Ignacio Soler Garcia Jun 28 '18 at 11:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.