3 ms·
The other problem w/ Code Contracts is inheritance. A call to base.DoStuff(arg); might fail, even though the child class handles it and doesn't need the contrac
by Scionwest 12y ago
The other problem w/ Code Contracts is inheritance. A call to base.DoStuff(arg); might fail, even though the child class handles it and doesn't need the contract to be satisfied by the parent.
- pjmlp 12y agoThat is not an issue. Have you read the whole principles behind code contracts? Derived classes must uphold the same contracts as the base classes, they are only allowed to strengthen them, not to drop conditions.
- richardw 12y agoIs there a difference between design-by-contract and the condition modifications allowed by the Liskov substitution principle? They seem related but I'm not well-enough versed in the differences. "...the subtype must meet a number of behavioral conditions. These are detailed in a terminology resembling that of design by contract methodology, leading to some restrictions on how contracts can interact with inheritance: Preconditions cannot be strengthened in a subtype. Postconditions cannot be weakened in a subtype. Invariants of the supertype must be preserved in a subtype." http://en.wikipedia.org/wiki/Liskov_substitution_principle http://en.wikipedia.org/wiki/Liskov_substitution_principle
- pjmlp 12y agoThey are the same. I was generalizing and though only about pre-conditions.