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, select Create Method > Behavior, and then select Opaque Behavior (or Activity).
  4. Click on the put Operation again, and open the Alf editor window (select Windows > Alf), if it isn't already open.
  5. Type the Alf code shown in the following figure.



  6. When the text is correct, click 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 new get Operation, select Create Method > Behavior, and then select Opaque Behavior (or Activity).
  4. Click on the get Operation again, and open the Alf editor window (select Windows > Alf), if it isn't already open.
  5. Type the Alf code shown in the following figure.



  6. When the text is correct, click 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