Smalltalk and Object Orientation: an Introduction - Free
Smalltalk and Object Orientation: an Introduction - Free
Smalltalk and Object Orientation: an Introduction - Free
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
classes, while object diagrams contain objects, but that it is possible to mix the two. However, they<br />
discuss both under the title class diagrams. Therefore, to avoid confusion, we adopt the term <strong>Object</strong><br />
Model to cover both sets of diagrams (followi ng the approach adopted in both the Booch <strong><strong>an</strong>d</strong> OMT<br />
methods).<br />
17.4.1 Classes <strong><strong>an</strong>d</strong> objects<br />
A class is drawn as a solid -outline rect<strong>an</strong>gle with three components. The class name (in bold type) is in<br />
the top part, a list of attributes (with optional types <strong><strong>an</strong>d</strong> initial val ues) in the middle part <strong><strong>an</strong>d</strong> a list of<br />
operations (with argument types <strong><strong>an</strong>d</strong> return values) in the bottom part. Figure 17.3 illustrates two<br />
classes, one for a class Car <strong><strong>an</strong>d</strong> one for a class File. The Car class possesses thr ee attributes called<br />
name, age <strong><strong>an</strong>d</strong> fuel. Their types are string, integer <strong><strong>an</strong>d</strong> string respectively. The class also possesses four<br />
operations start(), lock() <strong><strong>an</strong>d</strong> brake(), plus accelerate which takes a single parameter “to” which is <strong>an</strong><br />
integer <strong><strong>an</strong>d</strong> represents the new speed.<br />
Car<br />
name: string<br />
age: integer<br />
fuel: string<br />
start()<br />
lock()<br />
accelerate(to:integer)<br />
brake()<br />
File<br />
fileName: string<br />
size: integer<br />
lastUpdate: string<br />
print()<br />
Figure 17.3: Class with attributes <strong><strong>an</strong>d</strong> operations<br />
An attribute has a name <strong><strong>an</strong>d</strong> a type specified in the format name: type = initialValue. The name <strong><strong>an</strong>d</strong><br />
type are strings tha t are ultimately l<strong>an</strong>guage dependent. The initial value is a string representing <strong>an</strong><br />
expression in the target l<strong>an</strong>guage. Operations have a name <strong><strong>an</strong>d</strong> may take one or more parameters <strong><strong>an</strong>d</strong><br />
return a value. The format of <strong>an</strong> operation is name (parameter : type = defa ultValue, ...): resultType .<br />
The operation’s constituent parts are strings that are l<strong>an</strong>guage dependent.<br />
The attribute <strong><strong>an</strong>d</strong> operation compartments c<strong>an</strong> be hidden from view to reduce the detail shown in a<br />
diagram. Omitting a compartment says nothing about that part of the class definition. However, leaving<br />
a compartment bl<strong>an</strong>k implies that there are no definitions for that part of the class. Additional l<strong>an</strong>guage<br />
dependent <strong><strong>an</strong>d</strong> user-defined information c<strong>an</strong> also be included in each compartment in a textual format.<br />
The intention of such additions is to clarify <strong>an</strong>y element of the design in a similar m<strong>an</strong>ner to a comment<br />
in source code.<br />
The class stereotype c<strong>an</strong> be shown as a normal -font text string in between > centered above the<br />
class name (see Figure 17.4). A stereotype tells the reader what “kind” of class it is. Examples of<br />
stereotypes are exceptions, controllers, interfaces etc. However, UML makes no assumptions about the<br />
r<strong>an</strong>ge of stereotypes which exist <strong><strong>an</strong>d</strong> the designer is therefore free to develop their own. Other (l<strong>an</strong>guage<br />
specific) class properties c<strong>an</strong> also be indicated in the class name compartment. For example in Figure<br />
17.4 the Window class is <strong>an</strong> abstract class, thus the label abstract is printed below (<strong><strong>an</strong>d</strong> to the left) of the<br />
class name.<br />
140