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.

Car<br />

name<br />

hasEngine<br />

type<br />

Engine<br />

Golf : Car<br />

Petrol : Engine<br />

Figure 17.6: Association between classes / link between objects<br />

Each role (i.e. each end of the association) indicates the multiplicity of its class (i.e. how m<strong>an</strong>y<br />

inst<strong>an</strong>ces of the class c<strong>an</strong> be associated with one inst<strong>an</strong>ce of the other class). This is indicated by a text<br />

expression on the role. The expression c<strong>an</strong> either be a * (indicating zero or more), a number (e.g. 1), a<br />

r<strong>an</strong>ge (e.g. 0..3) or nothing (indicating exactly 1). These expressions are illustrated in Figure 17.7. It is<br />

also possible to specify that the multiple objects should be ordered using the text {Ordered}. It is also<br />

possible to <strong>an</strong>notate the association with additional text (such as {Sorted}) but this is primarily for the<br />

readers benefit <strong><strong>an</strong>d</strong> has no sem<strong>an</strong>tic me<strong>an</strong>ing in UML.<br />

In some situations it is sensible for associations to have attributes of their own. In these situations<br />

associations need to be treated as a class. Such a situation is illustrated in Figure 17.8. These<br />

associations have a dashed line from the association line to the association class. This class is just like<br />

<strong>an</strong>y other class <strong><strong>an</strong>d</strong> c<strong>an</strong> have a name, attributes <strong><strong>an</strong>d</strong> operations.<br />

1..<br />

*<br />

Wheels<br />

Wheels<br />

1<br />

1 or more<br />

0..1<br />

*<br />

Wheels<br />

Wheels<br />

Zero or 1<br />

Zero or more<br />

3..<br />

*<br />

{Ordered}<br />

Wheels<br />

Specifies ordering<br />

Figure 17.7: Types of association <strong>an</strong>notations<br />

In Figure 17.8 the associations possess <strong>an</strong> access permissions attribute which indicates the type of<br />

access allowed for each user for each file.<br />

File<br />

*<br />

AuthorizedFor<br />

*<br />

User<br />

Authorization<br />

Access Permissions<br />

/etc/termcap<br />

/usr/home/pah/.login<br />

(read)<br />

(read/write)<br />

Pheobe<br />

Pheobe<br />

Figure 17.8: Associations with attributes<br />

Aggregation represents part-whole relationships. That is, it indicates that one or more objects are<br />

dependent on <strong>an</strong>other object for their existence. For example, in Figure 17.9 the Micro Computer is<br />

formed from the Monitor, the System box, the Mouse <strong><strong>an</strong>d</strong> the Keyboard. All of these objects together<br />

are needed for the fully functioning Computer. Aggregation is actually represented as <strong>an</strong> empty<br />

diamond on the role attached to the whole object.<br />

142

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

Saved successfully!

Ooh no, something went wrong!