Step 2: Modeling Java Classes |
![]() Previous |
![]() Next |
This task takes you through the steps required to model Java classes, interfaces and associations on a class diagram.
OrderObservable
as the name for
the interface, and press Enter.
When you work with UML diagrams, you may occasionally see an ellipse (...) on an diagram element, for example, a class. This means that there is additional information that is not displayed because of the size of the element. To view it, resize the element.
observeOrder
and
press Enter. Order
as the name of the class, and add attributes orderRef
and customerContact
in the attributes compartment
(just below the first line), and the operations doInvoice
and doShip
in the operations compartment
(just below the second line).Order
and
OrderObservable
. Click the Realization
icon MyOrder
and the
operation overrideMethod
in the same way
as you modeled the previous class. Order
and MyOrder
. Click on the Generalization
icon MyOrder
and then
on Order
.as OrderEntrySystem
and the package as orderEntry
. Make sure
that Generate default constructor
and Generate
main method
are not selected.
When you click OK the Java class is displayed
in the Navigator, and the text of the class is displayed in the Editor window.
Edit the class in the Code Editor to add a field called currentOrder
of type Order
and a method called getCurrentOrder
with
a return type of Order
.
OEClassDiagram
button in the Document bar to display the diagram, then click on OrderEntrySystem
in the Navigator and drag it onto the diagram.OrderEntrySystem
to Order
.
Click the Directed 1..1 Association icon OrderEntrySystem
and then on Order
.OrderListener
and give it the attribute orderChanged
.Order
and OrderListener
. Click the Directed
1..1 Association icon Order
then on
OrderListener
. With the association highlighted
press Enter to display the Properties dialog. Select the Association
Ends tab then select Aggregate (Weak) from
the Aggregation drop-down box, then click OK.
This defines the 'from' end of the association as weakly aggregated.
Another way of displaying the Properties dialog for a diagram element is by selecting Properties from the context menu.
OrderFactory
with an operation OrderEntry
.HomeOrderFactory
and BusinessOrderFactory
.HomeOrderFactory
and OrderFactory
, and between BusinessOrderFactory
and OrderFactory
.OrderEntrySystem
and OrderFactory
. Cleared
, Packed
,
Shipped
and Invoiced
.
OrderState
, and make
Cleared
, Packed
,
Shipped
and Invoiced
inner classes of OrderState
. To make Cleared
an inner class of OrderState
, double-click
Cleared
to display the Properties
dialog. Click the In the Select Element dialog, expand the Model Elements node until you find OrderState which is the owning class, and select it.
Notice that the namespace of Cleared
now appears as orderEntry::OrderState
,
and that Cleared
appears in the inner
classes compartment of OrderState
.
Repeat this for Packed
, Shipped
and Invoiced
.
OrderFactory
and MyOrder
using the Dependency
icon OrderFactory
creates MyOrder
, and attach it to the dependency.
To attach the note click the Attach icon If you like, spend some more time working on the class diagram to add additional attributes and operations. For example, you could add the operation isCleared to the Java class Order. You can change the return type to boolean by editing the default of void on the class diagram.
Now that you have created the class diagram, you are ready to proceed to the next task, Step 3 - Generating Java Source Code from the Class Model, which shows you how to generate Java source code from the class diagram you have created.