Bertrand Meyer. Applying "Design by Contract". In IEEE Computer, October 1992. p40-51. (pdf).
Slide handouts.
JP: Chapter 13.
An important principle when designing a system is the notion of "design by contract". The first example Meyer uses in his paper is that of a delivery service. A client can get a package, which weights less than 5kg, and is less than 2m in each dimension, delivered all over Paris for 100 franks within 4 hours. Thus, the delivery agent do not have to worry about packages too big or too heavy, as they are not covered by the contract. The delivery agent will carry all sorts of things around Paris, but invariantly they are all of a certain size and weight, and invariantly they are delivered within 4 hours. The reputation of the delivery agent depends very much on the capability to always honour this invariant behaviour.
The papers do not use Java as their programming language. The notion of design by contract is independent of programming language. The lecture and exercises will be based on Java as usual.
I will also talk about the java notion of interfaces, so take a look at how interfaces work in JP chapter 13.
Consider the following class:
public class Haddock { private String greet = "You #!@ Miserable earthworms! Numbskulls! and Carpet-sellers!"; }
Haddock captain = new Haddock(); for(String s: captain) System.out.println("Haddock says: " + s);Should print:
Haddock says: You Haddock says: Miserable Haddock says: earthworms Haddock says: Numbskulls Haddock says: and Haddock says: Carpet Haddock says: sellers