Reading Contracts Flashcards
What is used to model each program type in Java (i.e. int double, String, NaturalNumber, etc.)?
A mathematical type - every variable of a certain program type has a value from its mathematical model’s mathematical space/domain
Mathematical type of boolean
boolean (true or false)
Mathematical type of char
character (‘A’, ‘?’, ‘z’, …)
Mathematical type of int
integer (-2147483648 through 2147483647)
Mathematical type of double
real (about 15 significant digits)
Mathematical type of String
string of character
Mathematical type of NaturalNumber
integer (non-negative)
Mathematical type of Queue<T>.</T>
String of T
Mathematical type of Sequence<T></T>
String of T
Mathematical type of Stack<T></T>
String of T
Mathematical type of Set<T></T>
finite set of T
Mathematical type of Map<K, V>
There are 2 ways to define the mathematical type of Map<K, V>:
1. finite set of ordered pairs of (K, V), with “function property” (i.e. the condition that no 2 pairs in the set have the same K value)
2. finite partial function from K to V
What constitutes a method contract? (Only name the parts)
A precondition (requires clause) and a postcondition (ensures clause)
Define precondition (requires clause)
A precondition (requires clause) is the part of a contract of a method that defines the responsibility of the program “calling” (using) that method (client code)
Define postcondition (ensures clause)
A postcondition (ensures clause) is the second part of a method that defines the responsibility of the program that implements that method (implementation code in the method body)