29.11.2014 Views

Smalltalk and Object Orientation: an Introduction - Free

Smalltalk and Object Orientation: an Introduction - Free

Smalltalk and Object Orientation: an Introduction - Free

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

12.6 The private-updating protocol<br />

Next we return to the inst<strong>an</strong>ce side of the class (by selecting the inst<strong>an</strong>ce radio button in the System<br />

Browser) <strong><strong>an</strong>d</strong> define each of the methods in the private-accessing protocol. Remember you MUST move<br />

back to the inst<strong>an</strong>ce side of the class by selecting the inst<strong>an</strong>ce radio button below the class list. Notice<br />

that the name of this protocol is comprised of two names “private” <strong><strong>an</strong>d</strong> “updating”. This is because, it is<br />

not intended for use by users of this class. Rather it is used by the initialize method to set up <strong>an</strong> inst<strong>an</strong>ce<br />

of this class. The methods there are ”private” to the object <strong><strong>an</strong>d</strong> are used for “updating” the state of the<br />

object.<br />

The addressBook: method is <strong>an</strong> updater method for the addressBook inst<strong>an</strong>ce variable. It is<br />

used to accept a new dictionary object to use for the addressBook. It is intended only for use with<br />

the inst<strong>an</strong>ce creation method of the Org<strong>an</strong>izer class.<br />

addressBook: aDictionary<br />

addressBook := aDictionary<br />

The appointments: method is <strong>an</strong> updater method for the appointments inst<strong>an</strong>ce variable. It is<br />

used to accept a new dictionary object to use for the appointments. It is intended only for use with<br />

the inst<strong>an</strong>ce creation method of the Org<strong>an</strong>izer class.<br />

appointments: aDictionary<br />

appointments := aDictionary.<br />

Finally, the notes: method gives the notes inst<strong>an</strong>ce variable a Bag to hold its contents.<br />

notes: aBag<br />

notes := aBag.<br />

Figure 12.5 illustrates the state of the System Full Browser at the end of these steps.<br />

Figure 12.5: The private-updating protocol<br />

12.7 The accessing protocol<br />

Now we will define the methods for the accessing protocol. First define the protocol then each of th e<br />

following methods in turn. We will first define the inst<strong>an</strong>ce variable accessors <strong><strong>an</strong>d</strong> then the Org<strong>an</strong>izer<br />

specific methods. As before, the accessor methods have the same name as the inst<strong>an</strong>ce variables. We<br />

will also define methods which are used to set the contents of inst<strong>an</strong>ce variables.<br />

The addNote: method adds a new note to the notes inst<strong>an</strong>ce variable.<br />

addNote: aNote<br />

notes add: aNote.<br />

The newAddress:for: method is used to add a new address to the address book. It is illustrated<br />

in Figure 12.6.<br />

107

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!