home  |   software development  |   user experience  |   training services  |   print  |   audio  |   contact  
 
Getting Started with ModelMaker
Tutorial 3 — Creating Classes Within Diagrams
 
 
Tutorial 3
Now that we‘ve visualized existing classes, we can examine how to create a new class within a diagram. As we mentioned earlier, the master views in ModelMaker (Classes View, Units View and Diagrams View) are all just different views into the same active model. This means that we can add a model element in any of these views — adding those elements is just a slightly different process in each view.
For our purposes, you can either use the class diagram from the previous topic or create a new one. As a point of convention, it‘s important to note the differences between a few of the tool buttons on the Class Diagram Editor toolbar (see figure 9). There are some buttons here that are common to all diagrams and we‘ll discuss these in the next tutorial.

Figure 9 — part of
the Class Diagram
Editor toolbar.
These four buttons are used to add classes and interfaces to the diagram. The first button will create a new class, adding it to the model and the diagram — we‘ll discuss that in a moment. The second button allows you to choose a class that already exists in the model, and add it to the diagram. The third creates a new interface, adding it to both the model and the diagram while the fourth button will add an existing interface to the diagram. For this topic, we‘ll focus on the first button.
Click this first button (actually the fourth from the left). The cursor will change to indicate that you‘re adding a class.
Click on the diagram where you would like to add the class. The Class Symbol editor will be displayed (see figure 10).

Figure 10 — the Class Symbol editor.
This editor allows you to define most every facet of a class — its role, appearance, documentation, etc. The Class Name field should be self-explanatory — enter your class‘ name here. Use the Ancestor drop-down to select an ancestor class. The other fields on this tab and the other tabs are optional; for now just set the first two fields and click OK. Your new class will appear in the diagram.
Press F3 (or select the Classes tab) to switch to the Classes View. If your diagram only contains the one class, drag some classes from the Classes View to the diagram to add them. Now notice that, as you select the various classes in your diagram, they become selected in the Classes View as well. In addition, their members are displayed in the Member List.
Your new class is rather empty, so let‘s add some properties. We need the Member List to add methods, events and simple properties and we‘ll be discussing that in Tutorial 5, but we can easily add class-type properties and fields in the Diagram Editor, so let‘s try that now. In the Class Diagram Editor, click the Add Property to Model tool button (8th from the left). Now click-and-hold in the class symbol to which you are adding the property, and drag to the class symbol whose type the property will be. For example, if you have a diagram containing the classes TmyClass and TmyNewPropertyType, to add a property to TmyClass of type TmyNewPropertyType, select Add Property to Model, then click on the TmyClass symbol and drag to the TmyNewPropertyType symbol. The Property Association dialog will appear (see figure 11).

Figure 11 — the Property Association dialog.
This is a complex dialog, but don‘t be daunted. Most the fields on this tab are the values you‘re used to entering in Delphi by hand: Name is the name of the new property, this defaults to the name of the properties class type. Use the Visibility group box to set the new property‘s visibility. The Data Type fields are disabled since, by adding a class-type property in the diagram, we already know the data type. The Read and Write Access group boxes allow you to set the methods of access for this new property. This is a very powerful and timesaving feature of ModelMaker; any accessor methods or state fields needed by this property are added automatically and are always kept up-to-date by ModelMaker. If you change the name of this property, ModelMaker will automatically update its accessors and/or state field.

Figure 12 — Automatically visualized Generalization relations.
Changing Relations in a Diagram
You may have noticed that when visualizing your classes, if a class is added to a diagram and that class‘ ancestor is also in the diagram, the Generalization relation is automatically visualized (see figure 12).
There are a great many options and wizards for advanced handling and automation of visualizations, but the Generalization relation is pertinent to our current topic, so for our final thought here, notice the following:
You can change the ancestor of a class, not just within the diagram but also for the whole model, from within a class diagram. Make sure you are editing a class diagram that contains 3 classes, one of which is descendant of another in the diagram. Open the Classes View (so you can see the results) by pressing F3. Click the Generalization arrow to select it. A “grabber” should appear at each end of the arrow (see figure 13).

Figure 13 — A Generalization arrow, selected.
To change the class‘ ancestor, click the grabber at the arrowhead, and drag the arrowhead to a different class. Notice in the Classes View that the ancestor of your class has changed. This is a good example of the interconnectedness of the various editors — they are all looking into the same active code model. Note that this same method can be used to change the class type of a class‘ property within a diagram; drag the Property relation to a new class to change the property‘s type.
This has been an incomplete view of diagramming and the class creation process. See Tutorial 4 for an overview of diagramming in ModelMaker and Tutorial 5 for an overview of the class implementation process.

Return to the Introduction.
Go back to the previous tutorial.
Go on to the next tutorial.