Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference in Contract.Requires and Contract.Ensures

Tags:

c#

contracts

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

  • Contracts.Ensures
  • Contract.Requires

Any additional explaination would be great

Using visual studio c#

like image 370
Christie Davis Avatar asked Oct 29 '13 00:10

Christie Davis


1 Answers

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].

like image 82
Nicholas Carey Avatar answered Sep 19 '22 14:09

Nicholas Carey