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.

8.4 Creating <strong>an</strong> inst<strong>an</strong>ce<br />

As was suggested in the class comment, create <strong>an</strong> inst<strong>an</strong>ce of the class <strong><strong>an</strong>d</strong> send it some messages. You<br />

c<strong>an</strong> do that by typing the code in Figure 8.5 into the Workspace <strong><strong>an</strong>d</strong> selecting it. Then use the do it<br />

option off the right mouse button menu (middle mouse button if you have a three button mouse).<br />

The result of running this code should be that the following is printed into the Tr<strong>an</strong>script:<br />

0<br />

Bob was 0 but now is 1<br />

Once you have done this <strong><strong>an</strong>d</strong> are happy with what is happening, why not try <strong><strong>an</strong>d</strong> ch<strong>an</strong>ge the method<br />

definitions or add a new inst<strong>an</strong>ce variable called address <strong><strong>an</strong>d</strong> define the appropriate methods for that<br />

variable.<br />

Figure 8.5: Creating <strong>an</strong> inst<strong>an</strong>ce of Person<br />

80

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

Saved successfully!

Ooh no, something went wrong!