This page provides directions to create the TimeTracker Model with MagicDraw. The model is shown below for your reference.
Person
class. It is always a good
idea to document your model. Documentation added to model elements such as classes,
attributes and methods is carried over to the code as comments. Double-click on
the Person class to bring up the Class Specification dialog. Add the following
sentence in the Documentation field and click OK:
"This class represents any person whose time needs to be tracked."
name
attribute of the
Person
class.
Right-click on this class and select Insert New Attribute. A new attribute is
inserted with the specification "-unnamed1". Write over this specification with
this new one: "+name : String" (be sure to delete the minus sign in front of the name).
This new specification indicates that
name
is an attribute of class
Person
with a platform independent type of String. Attributes are always
generated as private members of the class. However the visibility of the associated
property is determined by the visibility of the attribute specification. In this case
we have specified public visibility (by using the plus sign) and hence the
Name
property will be public.
rate
attribute to class
Person
.
However the type of this attribute is
Quantity
, which is an embedded value
representing a
value
and a
unit
. So let's first define the class
Quantity
. Add a new class called
Quantity
using the class icon
in the toolbar. Add two attributes to this class with specifications "+value : double" and
"+unit : String". Now we can add the attribute
rate
to class
Person
.
Add this attribute with the specification "+rate : Quantity"
Entity
to class
Person
. To do this, right-click on
the class and select Stereotype. In the next level menu, check Entity and click Apply. The
Person
class will now have the
Entity
stereotype.
EmbeddedValue
stereotype to class
Quantity
.
Timecard
as shown in the diagram. Remember that before entering
the attribute called
status
you will have to create its type, namely
TimecardStatus
, which has a stereotype of
Enumeration
.
Person
and
Timecard
.
To do this, click on the Association icon in the toolbar (13th icon from top). Click on the
Person
class, drag your mouse to the
Timecard
class and release the
mouse. A new association will be created. Right-click on the Person end of the association and
select the multiplicity of 1. Similarly set the multiplicity of the
Timecard
end to
many (*). Again right-click on the
Person
end of the association and select
Edit Name. Type the following specification for this association end: "+owner". Similarly
enter the following specification for the
Timecard
end of the association:
"+timecards".
TimeAllocation
as shown in the diagram above.
Timecard
and
TimeAllocation
.
Note that this is a special kind of association called Composition. To select a Composition
in the toolbar, you must right-click on the Aggregation icon (14th from the top) and select
Composition from the second level of icons.
Task
and its association relationship with class
TimeAllocation
.
TimeTracker
model by selecting File > Save Project.
Congratulations! You have now specified the key classes of the
TimeTracker
application.
We are now ready to generate some code. Please go back to the main tutorial page and contiue from
where you left off.