This tutorial section illustrates the following tasks:
•Add an abstract class to an existing class diagram
•Add class properties and operations, and define parameters as well as their direction and type
•Add a return type to an operation
•Change icons to UML conformant symbols
•Delete and hide class properties and operations
•Create a composite association between two classes.
To proceed, run UModel and open the BankView-start.ump project (see also Opening the Tutorial Project).
The diagram to which the abstract class will be added is called "BankView Main" and can be opened as follows:
1.In the Diagram Tree window, expand the "Class Diagrams" package to display all class diagrams contained in the project.
2.Do one of the following:
•Double-click the "BankView Main" diagram icon.
•Right-click the diagram, and select Open diagram from the context menu.
|Note:||It is also possible to open the diagram from the Model Tree window. First, locate the diagram under the package "Root | Design-phase | BankView | com | altova | bankview", and then use either of the methods above to open it.|
Two concrete classes with a composite association between them are visible in the class diagram.
"BankView Main" diagram
The new abstract class can be added as follows:
1.Click the Class toolbar button, and then click to the right of the Bank class to insert the new class.
2.Double-click the name of the new class and change it to Account.
3.In the Properties window, select the abstract check box to make the class abstract. The class title is now displayed in italic, which is the identifying characteristic of abstract classes.
4.In the code file name text box, enter "Account.java" to define the Java class.
1.Right-click the "Account" class and select New | Property, or press F7. A default property Property1 is inserted with stereotype identifiers << >>.
2.Change the property name to balance, and then enter a colon ( : ) character. A drop-down list containing all valid types is displayed.
3.Type "f", and press Enter to insert the return type "float". Note that drop-down lists are case sensitive.
4.Continue on the same line by appending "=0" to define the default value.
5.Using the same method as above, create a new property id of type String.
1.Right-click the Account class and select New | Operation, or press F8.
2.Enter "Account()" as operation name. Notice that the stereotype has changed to <<constructor>>, since the operation name is the same as the class name.
3.Using the same method as above, add two more operations, namely, getBalance():float and getId():String.
Let's now add a new operation which takes a parameter. We will also specify the parameter direction and type.
1.Press F8 to create another operation, collectAccountInfo().
2.Place the mouse cursor within the brackets and start typing "i". A drop-down list opens, allowing you to select the parameter direction: in, inout, or out.
3.Select "in" from the drop-down list, enter a space, and continue editing on the same line.
4.Enter "bankAPI" as parameter name and then a colon ( : ). A drop-down list opens, allowing you to select the parameter type.
5.Select IBankAPI from the drop-down list.
So far, the operation parameter has been added, but it does not have a return type yet. To add a return type:
1.Place the mouse cursor after the close parenthesis character ")" and enter a colon ( : ). A drop-down list opens, allowing you to select a return type.
2.Press the "b" key and select boolean as data type.
To specify an operation's visibility (for example, "private", "protected", "public"), click the icon preceding the operation name, and select the required value, for example:
The visibility "package" is applicable for Java. In C#, use "package" to specify visibility as "internal". For information about how UModel elements map to constructs in each language, see UModel Element Mappings.
The visibility icons can be changed to UML conformant symbols if necessary, as follows:
1.In the Styles window, select Project Styles from the top drop-down list.
2.Scroll down to the Show Visibility setting, and select UML Style.
Press F8 to add a dummy operation Operation1 to the Account class.
To delete the dummy operation, select it and then press Delete. (Alternatively, right-click it and select Delete from the context menu). A message box appears asking if you want to delete the element from the project. Click Yes to delete Operation1 from the class diagram as well as from the project.
To delete the operation from the class in the diagram, but not from the project, press the Ctrl+Delete. This hides the operation from the diagram, although it continues to exist in the project. Classes with hidden members are displayed with an ellipsis ( ... ) character, as shown below:
A class with hidden operations
To unhide the operation, double-click the ellipsis at the bottom of the class. A dialog box appears where you can choose the elements that should be visible on the diagram, for example:
"Visible elements" dialog box
It is possible to configure UModel not to display a message box when you attempt to delete an object from the diagram, as follows:
1.On the Tools menu, click Options.
2.Click the Editing tab.
3.Under Ask before deleting from project, clear the in diagrams check box.
1.Click the Composition toolbar button, and then drag from the Bank class to the Account class. The class is highlighted when the association can be made. A new property (Property1:Account) is created in the Bank class, and a composite association arrow joins the two classes.
2.Double click the new Property1 property in the Bank class and change it to "accounts", being sure not to delete the Account type definition (displayed in teal/green).
3.Press the End keyboard key to place the text cursor at the end of the line.
4.Enter the open square bracket character ( [ ) and select asterisk ( * ) from the dropdown list. This defines the multiplicity, namely, the fact that a bank can have many accounts.
Notice that the multiplicity range previously added to the diagram is also visible in the Properties window: