0

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.

2
  • By "one of the request" do you mean parameters to a controller that handles an HTTP request? Commented Jun 28, 2018 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. Commented Jun 28, 2018 at 13:43

1 Answer 1

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

2
  • Yeah, he reconsidered :) Commented Jun 28, 2018 at 10:49
  • I'm happy to hear that. Every time a programmer violates a SOLID principle a kitty dies. Commented Jun 28, 2018 at 11:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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