- How do we approach the specification of a program?
- There are many ways of doing this, some are quite formal, while others use simple
English statements
- The approach that we will use is based on the use of objects and operators
- Object: something that will be manipulated by the program or the user, a conceptual
entity that we want to do something with
- Operators: used to manipulate the objects, used to change the state of the objects
- We can specify an object by listing its properties - the data that is stored in the
object, plus any constraints on how this data can be changed
- We can specify the operators by using pre- and post-conditions;
pre-conditions
state the operator's assumptions, post-conditions state what the operator does:
how it changes the objects
- We start by specifying the objects (abstract datatypes) in the application
- We need some way of recording the phone number of an individual, this is done
by the phone_record object:
Object phone_record;
name : text;
number : text;
End;
- The complete phone book is given by the following object:
Object phone_book;
contents : set of phone_record;
End;
- There are two operators in this application
- The first operator is used to initialize the phone book, in other words read the
file containing the phone list
Operator read_phone_list;
Pre
phone_book.contents is empty;
Post
phone_book.contents is not empty;
End;
- The other operator looks up the number corresponding to a name
Operator look_up(name) -> number;
Pre
phone_book.contents has a phone record with name in it;
Post
the number returned is in the same phone_record as the name parameter;
End;