Smalltalk and Object Orientation: an Introduction - Free
Smalltalk and Object Orientation: an Introduction - Free
Smalltalk and Object Orientation: an Introduction - Free
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Window<br />
abstract<br />
+size : Area = (10,10)<br />
#visible : Boole<strong>an</strong> = false<br />
+$defaultSize : Rect<strong>an</strong>gle<br />
#$maxSize : Rect<strong>an</strong>gle<br />
-grid : GraphicsContext<br />
Key<br />
$ Class responsibility<br />
+ Public<br />
# Protected<br />
- Private<br />
+display() {abstract}<br />
+hide()<br />
+$new()<br />
-displayOn(grid)<br />
Figure 17.4: Class with additional <strong>an</strong>notations<br />
Attributes <strong><strong>an</strong>d</strong> operations c<strong>an</strong> also have their intended scope indicated in the c lass definition. This c<strong>an</strong><br />
be useful even for l<strong>an</strong>guages such as <strong>Smalltalk</strong> which do not support concepts such as Public, Private<br />
<strong><strong>an</strong>d</strong> Protected attributes <strong><strong>an</strong>d</strong> operations. The absence of <strong>an</strong>y symbol at all in front of <strong>an</strong> attribute or<br />
operation indicates that th e element is a public inst<strong>an</strong>ce attribute or operation for that class. The<br />
signific<strong>an</strong>ce of this depends on the l<strong>an</strong>guage. The r<strong>an</strong>ge of symbols currently supported is indicated in<br />
Figure 17.4 <strong><strong>an</strong>d</strong> combinations of symbols ca n be used to indicate (for example) that a method is a class<br />
side public method (such as +$new() - a class side operation intended for inst<strong>an</strong>ce creation).<br />
repMobile1 : Car<br />
name = XK8<br />
age = 1<br />
fuel = petrol<br />
Figure 17.5: An object (structured cloud)<br />
An object is drawn as a hexagon with straight sides <strong><strong>an</strong>d</strong> a slight peak at the top <strong><strong>an</strong>d</strong> bottom (as<br />
illustrated in Figure 17.5). For those familiar with the Booch clouds this c<strong>an</strong> be thought of as a<br />
structured cloud otherwise just accept that this is the object symbol 10 . The object symbol c<strong>an</strong> be divided<br />
into two sections. The top section indicates the name of the object <strong><strong>an</strong>d</strong> its class in the format<br />
objectName : className. For example, in Figure 17.5 the object is repMobile1 <strong><strong>an</strong>d</strong> the class is Car (see<br />
Figure 17.3 for the definition of the class Car). The object name is optional although the class name is<br />
compulsory. The lower compartment contain s a list of attributes <strong><strong>an</strong>d</strong> their values in the format name<br />
type = value (although the type is usually omitted). For example in Figure 17.5 the three attributes<br />
defined in Figure 17.3 for a Car have the values XK8, 1 <strong><strong>an</strong>d</strong> petrol. The bottom compartment c<strong>an</strong> be<br />
suppressed for clarity. It is also possible to indicate how m<strong>an</strong>y objects of a particular class are<br />
<strong>an</strong>ticipated. This is done by indicating the maximum value, r<strong>an</strong>ge etc. in the top compartment. The lack<br />
of <strong>an</strong>y number indicates that a single object is intended.<br />
17.4.2 Associations<br />
Relationships between classes <strong><strong>an</strong>d</strong> objects are represented by associations drawn as a solid line between<br />
classes or objects (for example see Figure 17.6). An association between classes may have a name with<br />
<strong>an</strong> optional small “direction arrow head” (which is drawn as <strong>an</strong> arrow head on the association) showing<br />
which way it is to be read. For example in Figure 17.6 the relationship is called hasEngine <strong><strong>an</strong>d</strong> is read<br />
from the class Car to the class Engine. In addition each end of <strong>an</strong> association is a role. Roles may have<br />
a name illustrating how its class is viewed by the other class. In Figure 17.6 the engine sees the car as<br />
being a name <strong><strong>an</strong>d</strong> the car sees the engine as being of a specified type (e.g. Petrol, Diesel, Electric etc.).<br />
10<br />
Note that as of September 1996, the 0.91 addendum to the UML states tha t objects are now drawn as rect<strong>an</strong>gles with the<br />
object name <strong><strong>an</strong>d</strong> its class name (separated by a colon) underlined. This is a major notational ch<strong>an</strong>ge which the authors of the<br />
UML wish to make so that they do not have to invent different symbols every time the y have a type (or class) - inst<strong>an</strong>ce<br />
relationship. However this me<strong>an</strong>s that the distinction between objects <strong><strong>an</strong>d</strong> classes in diagrams is minimal <strong><strong>an</strong>d</strong> c<strong>an</strong> easily lead to<br />
confusion. In <strong>an</strong> attempt to make objects clearly distinguishable in this, <strong><strong>an</strong>d</strong> subsequent cha pters, we shall continue to use the<br />
structured cloud symbol for objects.<br />
141