CSE 331: Procedural abstraction and specification
In this lecture, we will rebuild last lecture's Sum from methods
and ask how to know that a program built that way works. Code that
calls a method is a client of the method. A method
specification has a precondition, which the client must make
true when it calls the method, and a postcondition, which the
method must make true when it returns or throws. The method may
assume the precondition. A method meets its specification if
every call that begins with the precondition true ends with the
postcondition true.
Procedural abstraction is using a method through its specification alone. Procedural abstraction lets us argue that a large program works, one method at a time. We will also compare specifications. A specification S1 is stronger than a specification S2 if every implementation that meets S1 also meets S2. Choosing how strong to make a specification is part of designing a method. Finally, a client is correct if it works with every implementation that meets the specifications it relies on.