ISP does not apply to classes or objects, but strictly about interfaces, in particular, about interface design. This principle is designed to prevent the grouping of semi-connected methods in one interface, so that users do not need only a subset of these methods to implement the rest as empty functions (either throwing a NotImplementedException or leaving it literally empty: { } ). Thus, it is easier to implement more consistent classes and use interfaces more efficiently.
In your example, you combine the Counter class with the ICounter interface in a way that is not directly related to the concept of ISP:
- ISPs are real objects. You should not use "excessive" links to incoming parameters.
This is partly true (if I correctly interpret the concept of "overly"). However, as I said, ISP is not related to how to interact with real objects, but how to define a useful interface.
- ISPs are classes. If your class already uses the full interface, you do not need to restrict the reference type in certain methods. In this example, the ICounter interface is excessive.
This is not true. The fact that a class implements an interface does not mean anything if you create a dependency on a particular class, not an interface. Remember that the interface provides a decoupling of various parts of your program, forcing components to rely on contracts, and not on a specific implementation, which may change in the future. Using a particular class, you lose this advantage. And again, this is not entirely related to the concept of ISP.
- This architecture is completely wrong in terms of SOLID principles (then why?).
From an architectural point of view, with an emphasis on SOLID principles, I would suggest having a dependency on ICounter , not Counter , including IncrementAndSend as part of the interface definition.
source share