Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • 14
    Perfect to a T example of violating liskov substitution. Do not use inheritance here, and you'll be fine. Commented Oct 16, 2012 at 20:39
  • 9
    You might want to change it to: public Status Status { get; private set; }; otherwise the Close() method can be worked around. Commented Oct 16, 2012 at 20:52
  • 6
    Maybe it's just this example, but I see no material benefit to complying with the LSP. To me, this solution in the question is clearer, easier to understand, and easier to maintain than one the complies with LSP. Commented Oct 22, 2012 at 20:21
  • 5
    @BenLee It's not easier to maintain. It only looks that way because you're seeing this in isolation. When the system is large, making sure subtypes of Task don't introduce bizarre incompatibilities in polymorphic code which only knows about Task is a big deal. LSP isn't a whim, but was introduced precisely in order to help maintainability in large systems. Commented Mar 3, 2016 at 21:21
  • 12
    @BenLee Imagine you have a TaskCloser process which closesAllTasks(tasks). This process obviously doesn't attempt to catch exceptions; after all, it's not part of the explicit contract of Task.Close(). Now you introduce ProjectTask and suddenly your TaskCloser starts throwing (possibly unhandled) exceptions. This is a big deal! Commented Mar 3, 2016 at 21:24