difference in Contract.Requires and Contract.Ensures
Asked Answered
E

1

8

I've looked up the difference on the microsoft site but can't really see the difference. links to the website are below

Any additional explaination would be great

Using visual studio c#

Exosmosis answered 29/10, 2013 at 0:31 Comment(0)
P
9

Requires is a precondition, meaning that the condition specified must be true prior to the method being invoked. Ensures is a postcondition, meaning that the method guarantees that the condition specified will be true after the method call is complete.

Preconditions and/or postconditions may be violated while the method is executing: the tests are done upon entry to and exit from of the method, respectively. An invariate condition is a contract that says that the specified condition always holds true.

Read Bertrand Meyer's Object-Oriented Software Construction for more [much more] detail. This paper by Meyer is shorter [much shorter].

Piccard answered 29/10, 2013 at 1:23 Comment(1)
nice one. I would also suggest Provable Code or Code Contracts courses at pluralsight.com. They give a very nice drill down into design by contract using Microsoft Code ContractsLowpressure

© 2022 - 2024 — McMap. All rights reserved.