Lecture 12 Programming by Contract

Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design and Iterative Development (3rd Edition)

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
Copyright W. Howden 1 Lecture 13: Programming by Contract
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Copyright W. Howden 2 PreConditions and PostConditions • PreCondition – what you assume to be true before an operation or process • PostCondition – what you assert to be true after an operation or process • Contract: If Preconditions hold before, then Postconditions will hold afterwards
Background image of page 2
Copyright W. Howden 3 PreConditions and Data Validation • Precondition client’s responsibility • Input validation is not required • Documented so it does not slip through the cracks • Clarifies when and where data needs to be checked • Redundant checks lead to – decreased performance – less clarity – increased opportunity for errors
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Copyright W. Howden 4 Kinds of Postconditions • Low level – Conditions and relationships on variable values – Return value properties • Higher level – Objects created or deleted – Associations formed or deleted
Background image of page 4
Copyright W. Howden 5 Applications • Low level – Algorithms – Classes • class and method properties • Higher level – Use case assumptions and results – System and subsystem operations identified during requirements analysis and elaboration
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Copyright W. Howden 6 Algorithms and Pre/PostConditions • Formal specifications • Proofs of correctness of algorithms – verification, formal verification
Background image of page 6
Copyright W. Howden 7 Assertions • Assertion: Condition that should be true at an associated location in the algorithm • PreCondition= input assertion • PostCondition = output assertion • Intermediate assertion – intermediate state of system/program • Loop invariant = assertion about state at some location in a loop
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Copyright W. Howden 8 Algorithms and Verification Suppose that A 1 is the precondition for an algorithm A and A n is the postcondition. • Correctness: A is correct if it is partially correct and it always terminates • Partial correctness of A if A 1 is true at the beginning of A and if A is executed and terminates, then A n will be true at the end of the execution
Background image of page 8
Copyright W. Howden
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 32

Lecture 12 Programming by Contract - Lecture 13:...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online