We will now add two operations to the AddressBook class, one to put an entry into an AddressBook and another to look up an address for a name.


To add a put Operation to AddressBook


  1. Click on the AddressBook symbol on the Class Diagram. Click on the little Create Element button at the top right of the Class symbol, and select Operation.
  2. Type put as the name of the Operation and, inside the parentheses, type the parameter list name: String, address: String, then press Return.
  3. Click on the new put Operation, and, in the Alf editor window, press Create.
  4. Type the Alf code shown in the following figure.



  5. When the text is correct, press Save.


To add a get Operation to AddressBook


  1. Click on the AddressBook symbol on the Class diagram. Click on the little Create Operation button to the top right of the Operations compartment.
  2. For the operation and its signature, enter get(name: Sting): String[0..1] and press Return. (Make sure you don't leave the default "()" at the end of what you enter.)
  3. Click on the get Operation, and, in the Alf editor window, press Create.
  4. Type the Alf code shown in the following figure.



  5. When the text is correct, press Save.


You may want to consider yourself how to code a remove(name: String) Operation that removes an entry from an AddressBook.

Next: Testing the AddressBook