Creating an EMF Model using a Graphical Editor
Top
Previous: Creating Classes
Next: Generating the Model and Editor
Step 3: Creating Associations
-
In the editor view, click on the Association button
.
- Note that as you move your mouse pointer over a class, the class will change color. Click on the Library class.
- Next, move the mouse pointer over to the Writer class and click on it.
- As soon as you release the mouse button, the association properties dialog comes up.
On the 1st Association End tab, change the name to writers, select the Containment checkbox, and change the upper bound to -1.
The Containment property indicates that a Library object will contain Writer objects through this writers association. The upper bound of -1 means a Library object can own more than one Writer objet.
- Click on the 2nd Association End tab, and deselect the Navigable checkbox.
This indicates that from a Writer object, you cannot navigate to the Library object that owns it.
- Click on the Router tab, select the Manual radio button. The selections on this tab do not affect the properties of
the association in the ecore model. They only affect how the association line
is drawn in the editor. Click the OK button.
- An arrow is now drawn between the Library class and the Writer class. to represent the association we just created
- Now, we are going to create the containment association between Library and Book. It is similar to the association between Library and Writer.
Click on the
button and then on the Library class. Then click on the Book class. On the 1st Association End tab of the association properties dialog, change the name to books, select the Containment checkbox and change the upper bound to -1.
- On the 2nd Association End tab, deselect the Navigable checkbox. On the Router tab, select the Manual radio button. Click the OK button.
- Next we are going to create the association between Book and Writer.
Click on the Association button
, then click on the Book class and then click on the Writer class.
- On the 1st Association End tab, change the name to author. Leave the Containment checkbox unchecked, and change the lower bound to 1. We assume a book will have exactly one author.
- Click on the 2nd Association End tab. Change the name to books and change the upper bound to -1. A writer can author zero or more books.
- Click on the Router tab, select the Manual radio button and click the OK button. The association is drawn in the editor view.
- We can make the class diagram look tidier if we can make the line that represents the association between the Writer and Book classes be drawn so that it appears horizontal and
without the jagged edge. This can be done easily in the editor.
Click on the Writer class to select it. Next, holding down the Shift key, click on the Book class to add it to the selection.
- Right-click and select Alignment > Align Middle.
- Now, the diagram looks much neater. Press Ctrl+S key to save the model.
Top
Previous: Creating Classes
Next: Generating the Model and Editor