Lecture 14 Programing by Contract

Lecture 14 Programing by Contract - Copyright W. Howden 1...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: Copyright W. Howden 1 Programming by Contract CSE 111 01/08/11 Contracts Client and Supplier Contract: if client satisfies certain preconditions, then the supplier will produce a product satisfying certain postconditions Copyright W. Howden 2 01/08/11 Design by Contract All of the components (classes, methods and procedures) have a stated contract that they will fulfill Benefits reusable components correct interfaces when integrating components predictable results 01/08/11 Copyright W. Howden 3 Software Contracts Methods and procedures precondition: required input properties postconditions: guaranteed output properties, provided precondition is satisfied Classes method contracts class invariants properties that are true on completion of constructor and true before and after each method application 01/08/11 Copyright W. Howden 4 Assertions Expected properties of program state (values of variables) Used to specify preconditions, postconditions and class invariants Also used for intermediate assertions statements about what is expected to be true at intermediate points in a programs execution 01/08/11 Copyright W. Howden 5 Assertions and Preconditions Assertion should appear as first line in a method Asserts that whenever execution reaches this location, this property must be true 01/08/11 Copyright W. Howden 6 Assertions and Postconditions Executable dynamic testing assertions should appear before each return statement State that the asserted property is true whenever the program returns from that location Static assertions can be put after the return points 01/08/11 Copyright W. Howden 7 Assertions and Class Invariants Should appear as postconditions in constructors and all other methods Should appear as preconditions in all methods For public methods, input should be checked directly and not by an assertion assertions can be turned off after debugging 01/08/11 Copyright W. Howden 8 Assertion Languages Static analysis non-executable informal prose statements or formal statements in a formal logic Dynamic analysis executable expressions that return T or F executed during testing, but turned off during production use Copyright W. Howden 9 01/08/11 Validating Contracts Static: prove that if the precondition holds then when the program reaches termination, the postcondition holds Dynamic: use executable assertions for pre and postconditions. Run tests. If a postcondition does not hold when the precondition holds, the contract is not valid. If a precondition does not hold either a test is faulty or the program and/or precondition need to be corrected Copyright W. Howden 10 01/08/11 Lecture Topics Static analysis(verification) of method/procedure and class contracts sometimes called proofs of correctness Dynamic analysis (testing) with Java assertions pre and postconditions class invariants, etc....
View Full Document

This note was uploaded on 01/07/2011 for the course CSE 111 taught by Professor Howden during the Spring '07 term at UCSD.

Page1 / 52

Lecture 14 Programing by Contract - Copyright W. Howden 1...

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

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