UP | HOME
../../

Design by Contract (DbC) WIP

Table of Contents

1 Background

  1. Assertions
  2. Correct by Design

2 Contract?

  1. Imagine: You are subcontracting out the design and construction of subsystems (classes) or methods.
  2. Assigning blame across interfaces
  3. Details of method responsibilities

2.1 An Example Contract

  1. A contract can be satisfied in many ways
    1. a method can have many implementation satisfying the contract;
    2. Different performances (time, space, etc);
  2. A contract hides the implementation details
    1. We can change implementations.
    2. Caller's code Will work for any implementation that satisfies the contract

3 Techniques

3.1 Public Methods

  1. Weakest Pre-conditions requires for public methods
    1. The called method assumes precondition holds
    2. Avoiding constantly checking arguments
    3. The caller guarantees precondition holds
  2. Strongest Post-conditions ensures for public methods
    1. The called method guarantees postcondition
    2. The caller method is guaranteed postcondition

3.2 Class Invariants

  1. Consider only the public methods Their entry- exit- assertions. Rewrite, if nec, using and's (at the top level)
  2. The common portion across all the above is the class invariant
  3. Strongest Class invariant

4 Reference

  1. Bertrand Meyer. Applying "design by contract". IEEE Computer, 25(10):40–51, October 1992. http://se.ethz.ch/~meyer/publications/computer/contract.pdf Also in his book "Object-Oriented Software Construction". ../../PDF/design-by-contract-meyer-1992-markedUp.pdf marked-up by pmateti. Required Reading.
  2. Bertrand Meyer, ACM Webinar, Sep 2015. https://bertrandmeyer.com/2015/09/15/design-by-contract-acm-webinar-this-thursday/

5 End


Copyright © 2020 cecs.wright.edu/~pmateti 2020-09-15