I was chatting with my colleague the other day about the Liskov Substitution Principle and Design by Contract. We know the rule (copied from Wikipedia) is that Subclasses in an inheritance hierarchy are allowed to weaken preconditions (but not strengthen them) and strengthen postconditions and invariants (but not weaken them). But how can we make the rule easier to understand?
Let’s say company A wants to outsource a project. Company S, which is CMMI Level 3 certified and has already developed some projects for Company A, has started negotiating with Company A. Company S asks for $80,000 and offers to deliver the project in 4 months.
If you want to win the project, you must be at least CMMI Level 3 certified (strengthened invariants), you must charge no more than $80,000 (weakened preconditions), and you must deliver the project in no longer than 4 months (strengthened postconditions). In other words, you must provide better service than Company S in order to substitute it.