1

When reading about ISP, I keep running into examples where a class implementing an interface has a method that throws some type of not-implemented exception. Isn't this also a violation of LSP?

However, if ISP always comes down to cases where you have unsupported methods then you're always violating LSP at the same time making ISP redundant.

I'm guessing I'm missing something, so can someone provide a clear example where you're violating ISP and not violating LSP?

I'm guessing the answer might be related to the exact meaning of "no client should depend on methods it doesn't use". What is meant by client here? Is it a class that implements the interface or a class that has access to an object implementing that interface and may make calls on it?

blu
  • 829
  • 2
  • 7
  • 14
  • Does this [answer](https://stackoverflow.com/a/71528518/1371329) your question? ISP has nothing to do with unsupported methods, because it has nothing to do with method implementations. Here is Bob Martin's [original paper](https://drive.google.com/file/d/0BwhCYaYDn8EgOTViYjJhYzMtMzYxMC00MzFjLWJjMzYtOGJiMDc5N2JkYmJi) defining the ISP. Also see [the difference between LSP and ISP](https://stackoverflow.com/a/65499896/1371329). – jaco0646 Mar 26 '22 at 22:21
  • Thanks, I think that answers it. Looks like the client is the caller not the implementer. As for an unsupported method, it seems to always be a violation of LSP. Although ISP may say nothing about implementation, an unsupported method might be a sign that we have too large an interface. That's my current interpretation anyways. – blu Mar 27 '22 at 06:51
  • Only the clients determine the appropriate size of an interface. Implementations are entirely bound to the clients' requirements. Unsupported methods can be a heuristic for the LSP, but the LSP does not prohibit optional methods. The LSP is a [semantic](https://stackoverflow.com/a/61782186/1371329) principle, so a single line of code is insufficient to determine anything. – jaco0646 Mar 27 '22 at 14:30

0 Answers0