Page 28 : 32
Object-oriented Programming in C#
Contracts and Assertions
* Correctness
Software Qualities
Correctness
Specifications
* Specification with preconditions and postconditions
Logical expressions
Examples of preconditions and postconditions
An Assertion Language
* Responsibilities and Contracts
Questions Related to Responsibility
Division of Responsibilities
The highly responsible program
Responsibility division by pre and postconditions
Contracts
Everyday Contracts
Contracts: Obligations and Benefits
Obligations and Benefits in Sqrt
* Class Invariants
General aspects of contracts
Everyday invariants
An example of a class invariant
* Inheritance is Subcontracting
Inheritance and Contracts
Subcontracting
Class invariants in the triangle class hierarchy
Assertions in Abstract classes
* Design by Contract
Design by Contract
DBC and Programming Languages
Code Contracts in C# 4.0
* Loop Invariants
Loop Invariants
Design by Contract
Design by Contract
TM
(DBC) represents the idea of designing and specifying programs by means of assertions
Use of contracts in the phases and activities of software development
Design:
A pragmatic approach to program specification
Documentation:
Adds very important information to interface documentation of the classes
Implementation:
Guides and constrains the actual programming
Verification:
The program can be checked against the specification every time it is executed
Test:
Preconditions limit the testing work
The check of postconditions and class invariants do part of the testing work
End use:
Trigger exception handling if assertions are violated