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. An <strong>Object</strong> Oriented Org<strong>an</strong>izer<br />

12.1 <strong>Introduction</strong><br />

This chapter presents a detailed example application constructed using the collection classes. The<br />

Org<strong>an</strong>izer is in tended as <strong>an</strong> electronic personal Org<strong>an</strong>izer. It therefore possesses <strong>an</strong> address book, a<br />

diary (or appointments section) <strong><strong>an</strong>d</strong> a section for notes. The remainder of this chapter describes one way<br />

of implementing such <strong>an</strong> Org<strong>an</strong>izer. At the end of this chapter is a programming exercise for you the<br />

reader.<br />

12.2 The Org<strong>an</strong>izer<br />

This example involves more th<strong>an</strong> one class <strong><strong>an</strong>d</strong> has a more complex architecture th<strong>an</strong> <strong>an</strong>ything you have<br />

seen so far. The architecture is illustrated in Figure 12.1. This example illustrates <strong>an</strong>other import<strong>an</strong>t<br />

concept in object orientation, that of <strong>an</strong> object within <strong>an</strong> object. These are often referred to as part-of<br />

hierarchies, i.e. one object is part-of <strong>an</strong>other. This should not be confused with the cla ss hierarchy<br />

which is a kind-of hierarchy.<br />

<strong>an</strong>Org<strong>an</strong>izer<br />

addressBook<br />

Dictionary<br />

notes<br />

Bag<br />

appointments<br />

Dictionary<br />

Figure 12.1: The structure of <strong>an</strong>Org<strong>an</strong>izer <strong>Object</strong><br />

As illustrated in Figure 12.1 <strong>an</strong> inst<strong>an</strong>ce of the Org<strong>an</strong>izer class contains three other objects.<br />

These objects are held in the inst<strong>an</strong>ce variables addressBook, appointments <strong><strong>an</strong>d</strong> notes. The<br />

inst<strong>an</strong>ces within addressBook <strong><strong>an</strong>d</strong> appointments are dictionary objects, while the notes<br />

inst<strong>an</strong>ce variable holds a bag object.<br />

12.3 The class definition<br />

We shall put all Org<strong>an</strong>izer class in a class category called Org<strong>an</strong>izer Class. As illustrated in the<br />

above figure the class definition possesses three inst<strong>an</strong>ce variables, addressBook, appointments<br />

<strong><strong>an</strong>d</strong> notes. Figure 12.2 illustrates the class definition.<br />

104

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

Saved successfully!

Ooh no, something went wrong!