A good C# example, I think, is the various stream classes. The abstract Stream
class defines a number of methods that may not apply to derived classes. I'm thinking specifically of the Can[...]
methods, CanRead
, CanSeek
, CanTimeout
, etc. On the face of it, they're degenerate methods in a derived class they don't apply to, but they are aspects of a stream that don't necessarily need to be implemented. A method that refers to the Stream
abstract class can query CanRead
, for example, and react accordingly based on the result, even if it's a degenerate implementation, as long as the degenerate implementation returns the right answer. In this way, a Stream
implementation might have degenerate methods, but not violate LSP.