Creating an EMF Model using a Graphical Editor
Top
Previous: Creating a New Model
Next: Creating Associations
Step 2: Creating Classes
-
In the editor view, click on the Create a class button, and then click anywhere in the blank area. A New Class dialog will come up.
- Enter Library as the class name. Click the Finish button.
- A Library class will be drawn
in the main view. You can drag it around and place
it wherever you prefer.
Now, right-click on it and select New > Attribute.
- Enter name as the name of the attribute. Ensure that the other properties match what is shown below. Click the OK button.
- You have just created a class named Library with a String attribute named name.
- There
is also another way of creating classes. First, you click in the blank
area of the editor to deselect any class you might have selected. Then, right-click
in the blank area of the main view and select New > Class.
- Enter Writer as the class name and click the Finish button.
- Create the name attribute for the Writer class just like before. Right-click on Writer, select New > Attribute, then enter name for Name and click the OK button.
- Now we are going to create an enumeration class. You can click on the
button and then anywhere on the blank area, or right-click on the blank area and select New > Enumeration to bring up the New Enumeration dialog. Enter BookCategory as the name of the enumeration.
- For each of the three literals shown below, click on the Add... button, enter the name and value of the literals, and then click the OK button.
Name
|
Value
|
Mystery
|
0
|
ScienceFiction
|
1
|
Biography
|
2
|
- At this point, the New Enumeration dialog should appear as shown below. Click the Finish button.
- The BookCategory enumeration is created and shown in the editor.
- We are now going to create the Book class. Right-click on the blank area and select New > Class. Enter Book as the class name and click the Finish button. Then, with the Book class selected, right-click and select New > Attribute, enter title as the attribute name and click the OK button.
- With the Book class selected, right-click and select New > Attribute, and enter pages as the attribute name. Select EInt as the type and click the OK button.
- With the Book class selected, right-click and select New > Attribute, and enter category as the attribute name. Select BookCategory as the type and click the OK button.
- Now you should have created 4 classes in the library project.
- Save the model by selecting File > Save or simply press the Ctrl+S key.
Top
Previous: Creating a New Model
Next: Creating Associations