-
From model to code and back again with theRational Software
Delivery Platform V7, Part 1:Create, build, fuse, and design UML
2.1 modelsSkill Level: Intermediate
Eric Long ([email protected])Software EngineerIBM
01 May 2007
IBM's Rational Software Delivery Platform provides a completely
customizable,UML 2.1-based visual modeling and design tool that
enables architects, systemsanalysts, designers and others in the
development process to clearly document andcommunicate processes,
flows, and designs. Rational Software Modeler, RationalSystems
Developer, and Rational Software Architect also integrate with
other tools(such as WebSphere Business Modeler and Rational Testing
products) to supporttrue team-wide development. This series walks
you through some of the UML 2.1modeling capabilities of Rational
Software Modeler, Rational Systems Developer,and Rational Software
Architect. In this tutorial, you learn how to create a UML
2.1modeling project, build UML models, fuse models, and apply a
design pattern to amodel using Rational Software Modeler.
Section 1. Before you start
Rational Software Modeler helps you create, import, and edit
several different typesof the Unified Modeling Language (UML) 2.1
models and diagrams associated withthose models. You can create the
following "out-of-the-box" models and diagrams:
Use case model Activity diagrams State machine diagrams
Create, build, fuse, and design UML 2.1 models Trademarks
Copyright IBM Corporation 2007. All rights reserved. Page 1 of
32
-
Use case diagrams Analysis model
Class diagrams Sequence diagrams
Design model Class diagrams Communication diagrams Component
diagrams Composite structure diagrams Deployment diagrams Sequence
diagrams
Enterprise model Service design model
About this seriesThis two-part series is for business analysts,
architects, developers, or anyone whois interested in learning
about the new modeling, transformation, and reversetransformation
capabilities of IBM's Rational Software Delivery Platform. This
seriesdiscusses three IBM Software Delivery Platform products:
Rational Software Modeler Rational Systems Developer Rational
Application Developer Rational Software Architect
About this tutorialThis tutorial explains how to create a UML
2.1 modeling project, build UML models,fuse models, and apply a
design pattern to a model using Rational SoftwareModeler.
Objectives
developerWorks ibm.com/developerWorks
Create, build, fuse, and design UML 2.1 models Trademarks
Copyright IBM Corporation 2007. All rights reserved. Page 2 of
32
-
After completing this tutorial, you will know how to use
Rational Software Modeler tocreate a modeling project, create two
models, fuse two models together, and apply adesign pattern to a
model.
PrerequisitesIt is assumed that you have some understanding of
UML 2.1. Knowledge of UML 2.1diagrams will be helpful, but not
required.
System requirementsTo run the examples as demonstrated in this
tutorial, you need to have RationalSoftware Modeler installed.
If you don't already have a copy of Rational Software Modeler,
you can download afree trial version. See Resources for the
prerequisites for Rational Software Modeler.
Rational Software Modeler works best on a machine with 1 GB of
memory.
Section 2. Create UML modeling project and build twoUML
models
After installing Rational Software Modeler, you need to create a
modeling project tohold all of the models you will create.
Create a modeling projectCreating a project using Rational
Software Modeler is very straightforward.
1. Open Rational Software Modeler.
2. From the Window menu, select Open Perspective >
Other....
3. Select Modeling and click OK.
4. Make sure any other open projects are closed.5. From the File
menu, select New > Other....
ibm.com/developerWorks developerWorks
Create, build, fuse, and design UML 2.1 models Trademarks
Copyright IBM Corporation 2007. All rights reserved. Page 3 of
32
-
6. Expand Modeling and select UML Project, as shown below.Figure
1. New Project Wizard
7. Click Next.
8. In the UML Modeling Project window, name the project
Project1, asshown.Figure 2. UML Modeling Project
developerWorks ibm.com/developerWorks
Create, build, fuse, and design UML 2.1 models Trademarks
Copyright IBM Corporation 2007. All rights reserved. Page 4 of
32
-
9. Click Next.
10. In the Create a new UML model window, select the Blank
Modeltemplate.
11. In the File name: field, type Project1Model.
12. Select Freeform Diagram from the drop-down menu for Default
diagramtype.
13. Your window should look like Figure 3.Figure 3. Create a new
UML model
ibm.com/developerWorks developerWorks
Create, build, fuse, and design UML 2.1 models Trademarks
Copyright IBM Corporation 2007. All rights reserved. Page 5 of
32
-
14. Click Finish.
15. The new project should now appear in your Project Explorer
view, asshown below.Figure 4. Project Explorer view
developerWorks ibm.com/developerWorks
Create, build, fuse, and design UML 2.1 models Trademarks
Copyright IBM Corporation 2007. All rights reserved. Page 6 of
32
-
16. Close the Project1Model.emx editor that was automatically
opened bycreating a new project.
17. Close the Project1Model::Main editor that was automatically
opened bycreating a new project.
You successfully created a UML project. The next sections shows
how to create aUML model.
Create a UML model
1. In the Project Explorer view, right-click MyModel.2. Select
Add UML > Package, as shown below.
Figure 5. Add new UML Package
3. Type sample as the name and press Enter.
4. Project1Model::sample::Main should now be open in the editor
view. (Ifnot, try closing and reopening the editor.)Figure 6.
Sample package Main editor
ibm.com/developerWorks developerWorks
Create, build, fuse, and design UML 2.1 models Trademarks
Copyright IBM Corporation 2007. All rights reserved. Page 7 of
32
-
5. In the Palette, on the right side of the editor, click to
expand the Classcomponents.
6. Click Class.Figure 7. Palette
developerWorks ibm.com/developerWorks
Create, build, fuse, and design UML 2.1 models Trademarks
Copyright IBM Corporation 2007. All rights reserved. Page 8 of
32
-
7. Click anywhere in the Project1Model::sample::Main editor.
ibm.com/developerWorks developerWorks
Create, build, fuse, and design UML 2.1 models Trademarks
Copyright IBM Corporation 2007. All rights reserved. Page 9 of
32
-
8. Type YourClass for the class name, as shown below, and press
Enter.Figure 8. Main Editor
There are several different ways to add UML elements to your
diagram(for example, hover icons, the file menu, context menus, and
so on). Forthis tutorial, use the Palette, for consistency.
9. Right-click YourClass and select Add UML >
Attribute.Figure 9. Add UML attribute
10. Type yourAttribute:String, as shown below, and press
Enter.Figure 10. yourAttribute
11. Right-click YourClass and select Add UML > Operation.
developerWorks ibm.com/developerWorks
Create, build, fuse, and design UML 2.1 models Trademarks
Copyright IBM Corporation 2007. All rights reserved. Page 10 of
32
-
12. Type yourOperation() and press Enter.
13. Press CTRL+S to save all changes.
14. Your editor should now look like Figure 11.Figure 11. Main
editor
15. In the Palette, click Class.
16. Click anywhere in the Project1Model::sample::Main editor.17.
Type YourAssociatedClass1, then press Enter.
18. Follow the same steps to create another class
namedYourAccociatedClass2.
19. Your editor should now look like Figure 12.Figure 12. Main
editor
20. In the Palette, select the drop-down menu to the right of
Association andselect Directed Association, as shown below.
ibm.com/developerWorks developerWorks
Create, build, fuse, and design UML 2.1 models Trademarks
Copyright IBM Corporation 2007. All rights reserved. Page 11 of
32
-
Figure 13. Directed Association
21. Click-and-hold on YourClass.
22. Drag your mouse over YourAssociatedClass1.
23. press Enter.You could name the association, but just accept
the defaults and leavethis field blank.
24. Repeat the same steps to create a Directed Association
fromYourClass to YourAssociatedClass2.
25. Your editor should now look like Figure 14.Figure 14. Main
editor
developerWorks ibm.com/developerWorks
Create, build, fuse, and design UML 2.1 models Trademarks
Copyright IBM Corporation 2007. All rights reserved. Page 12 of
32
-
Right-click any blank space in the editor and select Arrange All
to haveRational Software Modeler auto-arrange the UML elements.
This featurecomes in handy when dealing with large modeling
diagrams.
26. Press CTRL+S to save all changes.
27. Close all diagrams in Rational Software Modeler.
Congratulations, you built your first UML Model. In the next
section you'll createanother UML project and model.
Create another UML project and modelBecause you've already done
this once, we'll continue without the screen captures.See the
previous sections if you need help.
1. From the File menu, select New > Other....
2. Expand Modeling and select UML Project.3. Click Next.
4. In the UML Modeling Project window, name the project
Project2.5. Click Next.
6. In the Create a New UML model window, select the Blank
Modeltemplate.
ibm.com/developerWorks developerWorks
Create, build, fuse, and design UML 2.1 models Trademarks
Copyright IBM Corporation 2007. All rights reserved. Page 13 of
32
-
7. In the File name: field, type Project2Model.
8. Select Freeform Diagram from the drop-down menu for Default
Diagram.
9. Click Finish.
10. Close the Project2Model.emx editor that was automatically
opened bycreating a new project.
11. Close the Project2Model::Main editor that was automatically
opened bycreating a new project.
12. In the Project Explorer view, right-click Project2Model and
select AddUML > Package.
13. Type sample as the package name and press Enter.
14. In Project2Model::sample::Main, create a new class named
YourClass.15. Create a new attribute named
anotherAttribute:String.
16. Create a new operation named anotherOperation().
17. Your Project2Model::sample::Main editor should now look like
Figure 15.Figure 15. Main editor
18. Press CTRL+S to save all changes.
19. Close all editors.
Section 3. Model fuse
developerWorks ibm.com/developerWorks
Create, build, fuse, and design UML 2.1 models Trademarks
Copyright IBM Corporation 2007. All rights reserved. Page 14 of
32
-
Model fusing is a new feature in Rational Software Modeler. You
can fuse models intwo different ways:
"Harvest" material from one UML model or code model, and "smart
paste"it into another UML model.
Combine two logical models into a single logical model.In this
section, you will use the new model fuse feature to fuse two
arbitrary UMLmodels together.
Fuse two UML models
1. In the Project Explorer view, expand both projects you
created earlier.2. Click Project1Model, press and hold CTRL, and
select Project2Model.3. Right-click Project2Model and select
Combine Models..., as shown
below.Figure 16. Project Explorer Model
ibm.com/developerWorks developerWorks
Create, build, fuse, and design UML 2.1 models Trademarks
Copyright IBM Corporation 2007. All rights reserved. Page 15 of
32
-
developerWorks ibm.com/developerWorks
Create, build, fuse, and design UML 2.1 models Trademarks
Copyright IBM Corporation 2007. All rights reserved. Page 16 of
32
-
4. In the Combine Models window, as shown in Figure 17,
selectProject1/Project1Model.emx.Figure 17. Combine Models
5. Click OK.
6. The Visual Combine editor is now open, as shown below.Figure
18. Visual Combine editor
ibm.com/developerWorks developerWorks
Create, build, fuse, and design UML 2.1 models Trademarks
Copyright IBM Corporation 2007. All rights reserved. Page 17 of
32
-
developerWorks ibm.com/developerWorks
Create, build, fuse, and design UML 2.1 models Trademarks
Copyright IBM Corporation 2007. All rights reserved. Page 18 of
32
-
The Pending changes: view lists all of the changes that can be
made tothe target model in order to combine it with the source.
The Source: and Target: views show these changes visually, with
linksbetween the source and target to show where the effects of a
particularchange will be located. You can use the arrows in the
upper right of thePending changes: view to navigate through the
changes and decidewhich to accept, or not.
7. Check the following two boxes in the Visual Combine editor
underChanges related to sample Package:
Add anotherAttribute... Add anotherOperation()...
8. Your Visual Combine editor should now look like Figure
19.Figure 19. Visual Combine editor
ibm.com/developerWorks developerWorks
Create, build, fuse, and design UML 2.1 models Trademarks
Copyright IBM Corporation 2007. All rights reserved. Page 19 of
32
-
developerWorks ibm.com/developerWorks
Create, build, fuse, and design UML 2.1 models Trademarks
Copyright IBM Corporation 2007. All rights reserved. Page 20 of
32
-
9. Click OK.
10. In the File Changed window, click Yes.Figure 20. File
Changed window
11. In the Project Explorer view, expand Project1 to see the
"fused" result, asshown in Figure 21.Figure 21. Project Explorer
results
Notice that anotherAttribute and anotherOperation() have
beenadded to Project1Model.
ibm.com/developerWorks developerWorks
Create, build, fuse, and design UML 2.1 models Trademarks
Copyright IBM Corporation 2007. All rights reserved. Page 21 of
32
-
12. In the Project Explorer view, double-click the Main editor
in the samplepackage.
13. Right-click any blank spot in the editor and select Arrange
All.
14. Your editor should now contain the fused attribute and
operation, asshown below.Figure 22. Fused model
15. Press CTRL+S to save all changes.
16. Close all editors.
Great! You now know how to combine two arbitrary models using
Rational SoftwareModeler's new model fuse capability.
Section 4. Apply a design pattern to a UML model
In this section you'll apply the Observer design pattern to the
fused model createdearlier.
1. In the Project Explorer view, open the
Project1Model::sample::Maineditor.
developerWorks ibm.com/developerWorks
Create, build, fuse, and design UML 2.1 models Trademarks
Copyright IBM Corporation 2007. All rights reserved. Page 22 of
32
-
2. From the main menu, select Window > Show View >
Other..., as inFigure 23.Figure 23. Show View
3. Expand the Modeling folder and select Pattern Explorer.
4. Click-and-drag the Pattern Explorer view to the right side of
the screen.
5. In the Pattern Explorer view, expand Design Patterns >
Behavioral andselect Observer, as shown below.Figure 24. Pattern
Explorer
ibm.com/developerWorks developerWorks
Create, build, fuse, and design UML 2.1 models Trademarks
Copyright IBM Corporation 2007. All rights reserved. Page 23 of
32
-
The Pattern Explorer view contains a variety of different design
patterns,including all of the Gang of Four classics. Use the tabs
on the bottom forhelp: Overview (UML notation), or Short
Description of the designpattern. You can also create and share
your own design patterns usingthe Pattern Authoring view.
developerWorks ibm.com/developerWorks
Create, build, fuse, and design UML 2.1 models Trademarks
Copyright IBM Corporation 2007. All rights reserved. Page 24 of
32
-
6. In the Pattern Explorer view, click-and-drag Observer onto a
blank spot inyour editor, as in Figure 25.Figure 25. Observer
Pattern
You can now see an abstraction of the Observer design pattern in
UMLnotation. You need to bind classes to both a ConcreteSubject and
aConcreteObserver. In this example, the subject will be YourClass
andthe observers will be the two associated classes.
7. In the Project1Model::sample::Main editor, click-and-drag
YourClass ontothe ConcreteSubject section of the Observer
pattern.Figure 26. Add ConcreteSubject
ibm.com/developerWorks developerWorks
Create, build, fuse, and design UML 2.1 models Trademarks
Copyright IBM Corporation 2007. All rights reserved. Page 25 of
32
-
8. Now, click-and-drag both YourAssociatedClass1
andYourAssociatedClass2 onto the ConcreteObserver section of
theObserver pattern.
9. Right-click on a blank space in your editor and select
Arrange All. Youreditor should look like Figure 27.Figure 27.
Observer Pattern
developerWorks ibm.com/developerWorks
Create, build, fuse, and design UML 2.1 models Trademarks
Copyright IBM Corporation 2007. All rights reserved. Page 26 of
32
-
10. Right-click on a blank spot in the editor and select Select
> All.
11. Right-click YourClass and select Filters > Show Related
Elements....
12. In the Custom Query: list, select Show All Relationships
[Default].13. Change the Select in Model(s): drop-down to
Project1Model.14. The Show Related Elements in Diagram window
should look like Figure
28.Figure 28. Related Elements
ibm.com/developerWorks developerWorks
Create, build, fuse, and design UML 2.1 models Trademarks
Copyright IBM Corporation 2007. All rights reserved. Page 27 of
32
-
15. Click OK.
16. Right-click on a blank space in your editor and select
Arrange All.
17. Your editor should now look like Figure 29.Figure 29.
Observer Pattern
developerWorks ibm.com/developerWorks
Create, build, fuse, and design UML 2.1 models Trademarks
Copyright IBM Corporation 2007. All rights reserved. Page 28 of
32
-
You can see all of the relationships between the design pattern
and thebound classes.
18. Press CTRL+S to save all changes.
19. Close all editors.
Section 5. Summary
ibm.com/developerWorks developerWorks
Create, build, fuse, and design UML 2.1 models Trademarks
Copyright IBM Corporation 2007. All rights reserved. Page 29 of
32
-
Congratulations! In this tutorial you created two UML modeling
projects, built twoUML 2.1 models, fused two UML models together
using the new model fuse feature,and added a design pattern to the
fused model. The examples showed how easy itis to use Rational
Software Modeler to create meaningful UML 2.1 models
anddiagrams.
In Part 2 of this series, you'll learn how to use Rational
Software Architect totransform your model into Java source code,
edit the source code using UMLvisualization capabilities, and
reverse transform the changes back into your model.
developerWorks ibm.com/developerWorks
Create, build, fuse, and design UML 2.1 models Trademarks
Copyright IBM Corporation 2007. All rights reserved. Page 30 of
32
-
ResourcesLearn
Visit the developerWorks Rational zone to expand your Rational
skills. "Visualize with Rational Application Developer"
(developerWorks, Feb 2006)
details the visual tools available to visualize a number of
different Javaelements in Rational Application Developer.
"Visualize with Rational Software Architect" (developerWorks,
Mar 2006)discusses the visual tools available to create UML
projects and models,applying design patterns to those models (new
or existing), and transformingUML models into source code or into a
different type of model.
"Discover IBM Rational visual tools for application
development"(developerWorks, Feb 2006) details the visual tools
available to visualize dataelements in Rational Application
Developer.
IBM developerWorks Live! briefings are wonderful events for
continued learningon a variety of emerging technologies from IBM
and the open sourcecommunity.
Get products and technologies Download a free trial version of
Rational Software Modeler V7.0. Download a free trial version of
Rational Systems Developer V7.0. Download a free trial version of
Rational Software Architect V7.0. Build your next development
project with IBM trial software, available for
download directly from developerWorks.Discuss
Participate in developerWorks blogs and get involved in the
developerWorkscommunity.
About the authorEric Long
Eric Long is a software engineer in the IBM Developer Skills
Program.Eric graduated from the University of Texas with a degree
in ComputerScience, and currently works in Austin, Texas. He
provides technicalinformation to developers on emerging open source
and industry trendsand technologies through world-wide technical
briefings, speakingengagements, workshops, Web content, and faculty
consultations at
ibm.com/developerWorks developerWorks
Create, build, fuse, and design UML 2.1 models Trademarks
Copyright IBM Corporation 2007. All rights reserved. Page 31 of
32
-
IBM Academic Initiative member universities. His work also
includestechnical demos and content available at ibm.com/university
andibm.com/developerWorks.
developerWorks ibm.com/developerWorks
Create, build, fuse, and design UML 2.1 models Trademarks
Copyright IBM Corporation 2007. All rights reserved. Page 32 of
32
Table of ContentsBefore you startAbout this seriesAbout this
tutorialObjectivesPrerequisitesSystem requirements
Create UML modeling project and build two UML modelsCreate a
modeling projectCreate a UML modelCreate another UML project and
model
Model fuseFuse two UML models
Apply a design pattern to a UML modelSummaryResourcesAbout the
author