Create Associations

In this section we will learn how to create associations between entities. We will start out by modeling a Timecard entity and then creating two associations between Timecard and Person. The completed model will be as shown below.

The Timecard has three attributes:

  1. status: an enumeration with 4 values as shown
  2. begDate: the beginning date of the timecard, which should fall at the start of a week
  3. comments: comments added by the submitter and/or the approver of the timecard

The Timecard has two associations with Person:

  1. submitter: the person who has submitted the timecard
  2. approver: the person who will approve the timecard

The arrows on the two associations indicate that both associations are navigable from Timecard to Person, i.e. the timecard keeps references to its submitter and approver. Note that two-way navigability is indicated by not having arrows at either end of the association. The "1" and "*" at each end of the association indicate their multiplicity. The top association means one person can submit many (indicated by "*") timecards. Similarly the bottom association means one person can approve many timecards.

We are now ready to add these additional elements to our TimeTracker model. To do this, click the link below for your UML modeling tool.

ArgoUML MagicDraw

Generate Code

Follow the steps below to generate code.

  1. Open a Command Prompt and change your directory to C:/timetracker.
  2. Execute the command maven -o clean install. Make sure you get a BUILD SUCCESSFUL message.

Open the folder C:/timetracker/core/target/src/org/andromda/timetracker/domain in Windows Explorer. You will see 7 new files in there all related to the timecard entity. Review these files. Note that the Timecard class contains two references to the Person class, but the Person class contains no references to the Timecard class. This is because both associations between these classes are one-way from Timecard to Person.

What's Next?

At this point we have covered most of the important modeling concepts. In the next section we will add the remaining functionality to the TimeTracker model. Click here to get started.