exercise class diagram
DESCRIPTION
useful for class diagram and ooad projectTRANSCRIPT
Rational Application Developer v6.x Migration Student Exercise Guide
Copyright 2005, OnsiteSeminar LLC Rational Application Developer v6.x Migration All rights reserved, no unauthorized duplication Student Exercise Guide E-1
Revision: April 1, 2005
Exercise: UML Class Diagram
Exercise Description
The Eclipse open source project includes a component called the Eclipse Modeling Framework (EMF) that allows users to define models and generate a Java-based skeleton implementation. The RAD toolset also supports open standards in the area of model driven development. The introduction of the Universal Modeling Language (UML) visualization tool in WebSphere® Studio V5.1 and into RAD v6.0 provides us with the ability for developing a Java™ application based on a Rational Rose® class diagrams. In completing the exercise, the student should reference the student notebook, their individual notes and instructor answers to their questions. Exercise Duration This exercise will require approximately 45 minutes. Exercise Objectives
Upon successful completion of this exercise, the student should be able to:
• Create a Java project • Build a new UML Class diagram • Insert different types of UML relationships • Depict the generation of Java class source code
Rational Application Developer v6.x Migration Student Exercise Guide
Copyright 2005, OnsiteSeminar LLC Rational Application Developer v6.x Migration All rights reserved, no unauthorized duplication Student Exercise Guide E-2
Revision: April 1, 2005
Exercise: JSF Validation Exercise Instructions UML Class Diagram In this exercise, we will be developing a UML Class diagram that depicts the architecture of a Banking application. This application will incorporate the following Java classes with the appropriate types of class relationships:
Step 1: New Dynamic Web Project UML Class diagrams can be created within the Web Application perspective. This perspective provides views and tools that are appropriate for using the Visual Modeler for developing a subsection of UML diagrams in our Java applications.
__ 1) First, switch to the Web perspective, select Window à Open Perspective à Web
from the main menu. This will display the Select Perspective window. Select the Web perspective.
Rational Application Developer v6.x Migration Student Exercise Guide
Copyright 2005, OnsiteSeminar LLC Rational Application Developer v6.x Migration All rights reserved, no unauthorized duplication Student Exercise Guide E-3
Revision: April 1, 2005
__ 2) Next, we need to create a new Dynamic Web Project, select File à New à Dynamic
Web Project from the main menu. Enter BankWeb as the project name and BankWebEAR as the enterprise project name.
Click Finish button. Step 2: Create Class Diagram In this section, we will create six different classes that represent our application (Customer, Account, InvestementAccount, SavingAccount, Stock, StockOrder). __ 1) Our first step is to initiate the Visual Modeler and create the initial Class Diagram.
Highlight the BankWeb project, right click the mouse and select New à Other to open the wizard. Then open the Modeling folder:
Rational Application Developer v6.x Migration Student Exercise Guide
Copyright 2005, OnsiteSeminar LLC Rational Application Developer v6.x Migration All rights reserved, no unauthorized duplication Student Exercise Guide E-4
Revision: April 1, 2005
Select the Class Diagram option and click Next button and enter BankClassdigram as the
filename for the Class diagram. Click Finish button. __ 2) The Visual Modeler is now open with the corresponding Palette panel. Open the Java
folder on the Palette, select the Class option (by clicking on it) and then click on the Visual Modeling panel. This will open the New Java Class wizard:
Rational Application Developer v6.x Migration Student Exercise Guide
Copyright 2005, OnsiteSeminar LLC Rational Application Developer v6.x Migration All rights reserved, no unauthorized duplication Student Exercise Guide E-5
Revision: April 1, 2005
Enter Customer as the classname and bank as the packagename.
Click Finish button. This will add the Customer class to the diagram.
__ 3) Repeat this process for the following classes: o Account o SavingAccount o InvestmentAccount o Stock o StockOrder
__ 4) The completed diagram should appear as: Step 3: UML Relationships Now that we have created the six different classes that comprise our application, we need to build the relationships between these classes (Generalization, Association and Dependency. Additionally, we will need to define the attributes of our different classes
Rational Application Developer v6.x Migration Student Exercise Guide
Copyright 2005, OnsiteSeminar LLC Rational Application Developer v6.x Migration All rights reserved, no unauthorized duplication Student Exercise Guide E-6
Revision: April 1, 2005
__ 1) We need to build an Association relationship between the Customer and Account
classes in our UML Class diagram. First, we will create an attribute, highlight the Account class, right click the mouse and select Add Java à Field from the context menu.
Enter accounts as the attribute name, set the type to bank.Account (via the Browse button),
set the Dimensions to a value of 1 and visibility of private. Click Finish button. __ 2) Next, we need create another attribute, highlight the Customer class, right click the
mouse and select Add Java à Field from the context menu. Enter customer as the attribute name, set the type to bank.Customer (via the Browse button), set the Dimensions to a value of 0 and visibility of private. Click Finish button.
__ 3) Now, we need to generate the getter and setter methods for our attributes. Double-click
on the Account class in the diagram to open the source in the editor. Select the accounts attribute in the outline view (it appears in the lower left-hand corner), right click the mouse and select the Source à Generate Getters and Setters from the context menu:
Rational Application Developer v6.x Migration Student Exercise Guide
Copyright 2005, OnsiteSeminar LLC Rational Application Developer v6.x Migration All rights reserved, no unauthorized duplication Student Exercise Guide E-7
Revision: April 1, 2005
Click OK button. __ 4) Double-click on the Customer class in the diagram to open the source in the editor.
Select the customer attribute in the outline view, right click the mouse and select the Source à Generate Getters and Setters from the context menu.
__ 5) Now, we need to create an Association relationship between the Account and
Customer classes in our diagram. In the Palette, click on the Association option in the Java folder, then click on the Account class and drag the mouse and point to the Customer class, the following panel will appear to define our Association:
Rational Application Developer v6.x Migration Student Exercise Guide
Copyright 2005, OnsiteSeminar LLC Rational Application Developer v6.x Migration All rights reserved, no unauthorized duplication Student Exercise Guide E-8
Revision: April 1, 2005
Enter customer as the name and set the Dimension to 0. Click Finish button. __ 6) Now, we need to create an Association relationship between the Customer and
Account classes in our diagram. In the Palette, click on the Association option in the Java folder, then click on the Customer class and drag the mouse and point to the Account class, in the panel defining our Association enter account as the Name and set the Dimensions value to 1. Click Finish button.
__ 7) The UML Class Diagram will depict the Association relationship as:
Rational Application Developer v6.x Migration Student Exercise Guide
Copyright 2005, OnsiteSeminar LLC Rational Application Developer v6.x Migration All rights reserved, no unauthorized duplication Student Exercise Guide E-9
Revision: April 1, 2005
__ 8) Now, we need to create an Association relationship between the InvestmentAccount
and Stock classes in our diagram. In the Palette, click on the Association option in the Java folder, then click on the InvestmentAccount class and drag the mouse and point to the Stock class, the following panel will appear to define our Association:
Enter stock as the name and set the Dimension to 1. Click Finish button. __ 9) Double-click on the InvestmentAccount class in the diagram to open the source in
the editor. Select the stock attribute in the outline view, right click the mouse and select the Source à Generate Getters and Setters from the context menu.
__ 10) The Association relationship will be depicted as:
Rational Application Developer v6.x Migration Student Exercise Guide
Copyright 2005, OnsiteSeminar LLC Rational Application Developer v6.x Migration All rights reserved, no unauthorized duplication Student Exercise Guide E-10
Revision: April 1, 2005
__ 11) Now, we need to create an Association relationship between the StockOrder and
Stock classes in our diagram. In the Palette, click on the Association option in the Java folder, then click on the StockOrder class and drag the mouse and point to the Stock class, in the panel defining our Association enter stock as the Name and set the Dimensions value to 0. Click Finish button.
__ 12) Double-click on the StockOrder class in the diagram to open the source in the editor.
Select the stock attribute in the outline view, right click the mouse and select the Source à Generate Getters and Setters from the context menu.
__ 13) The UML Class Diagram will depict the Association relationship as: __ 14) Next, we add some additional attributes using the Add Java à Field from the context
menu for our different Classes in our diagram. Use the following table to identify which attributes to add to which class:
To create the getXXX and setXXX methods, select the attribute in the outline view, right click the mouse and select the Source à Generate Getters and Setters from the context menu.
Class Attribute name Type Generate getter and setter
Customer address java.lang.String yes
Account cashBalance double yes
SavingAccount interestRate double yes
Stock ticker java.lang.String yes
Stock quantity int yes
StockOrder commission double yes
Rational Application Developer v6.x Migration Student Exercise Guide
Copyright 2005, OnsiteSeminar LLC Rational Application Developer v6.x Migration All rights reserved, no unauthorized duplication Student Exercise Guide E-11
Revision: April 1, 2005
__ 15) Use Ctrl-S to save your updates. __ 16) Now, we need to create a Dependency relationship between the InvestmentAccount
and the Account classes in our diagram. Click on the InvestmentAccount, right click the mouse and select Add Java à Method.
Set the methodname to placeOrder, return type is void and the passed parameter will be a
StockOrder object. Click Finish button. __ 17) By default, Dependency relationships are not shown on the diagram. To display this new
relationship, right click from the InvestmentAccount class and select Filters à Show/Hide Relationships. From the panel select the Dependency option under the Java folder:
Rational Application Developer v6.x Migration Student Exercise Guide
Copyright 2005, OnsiteSeminar LLC Rational Application Developer v6.x Migration All rights reserved, no unauthorized duplication Student Exercise Guide E-12
Revision: April 1, 2005
Click OK button. __ 18) The updated diagram should now reflect the Dependency relationship:
Rational Application Developer v6.x Migration Student Exercise Guide
Copyright 2005, OnsiteSeminar LLC Rational Application Developer v6.x Migration All rights reserved, no unauthorized duplication Student Exercise Guide E-13
Revision: April 1, 2005
__ 19) The last relationship that we need to create is a Generalization relationship between the
Account, InvestmentAccount and SavingAccount classes. In the Palette area, click on the Extends option in the Java folder, select the InvestmentAccount in the diagram and then drag and drop the mouse on the Account class.
__ 20) Repeat this process for the SavingAccount class and create a Generalization
relationship between it and the Account class. The completed diagram should now appear as: