Modeling - UML Startup - Basics in Rhapsody

Transcription

Modeling - UML Startup - Basics in Rhapsody
UML Start-Up
Training
Basics in Rhapsody
Index
Rhapsody History
Product variants
Basic modeling
Exercise Stopwatch
Exercise Dishwasher
Exercise Dishwasher
System
The Tool:
IBM® Rational® Rhapsody®
Rational Rhapsody, a modeling environment based on UML, Rhapsody is a visual
development environment for systems engineers and software developers
creating real-time or embedded systems and software. Rational Rhapsody uses
graphical models to generate software applications in various languages including
C, C++, Ada, Java and C#.
History
Rhapsody was first released in 1996 by Israeli software company I-Logix Inc.
Rhapsody was developed as an object-oriented tool for modeling and executing
Statecharts, based on work done by David Harel at the Weizmann Institute of
Science.
In 2006, I-Logix's shareholders sold the company to Swedish software company
Telelogic AB. In 2008, Telelogix AB was acquired by IBM, consequently Rhapsody
became a Rational Software product, like all former Telelogic products.
Product variants
IBM® Rational® Rhapsody® ist available in different variants:
• Architect for Systems Engineers
• Architect for Software
• Designer for Systems Engineers
• Developer
• Design Manager
The characteristics of the first 4 variants can (as a thumb rule) be described with the following matrix:
SysML
UML
modeling
model simulation
Architect for
System Engineers
Designer for Systems
Engineers
Architect for Software
Developer
The Design Manager variant is part of the Jazz family, and will not be discussed here.
Target language
One of Rhapsody’s most valued features is the ability to generate code. There are different target languages
possible:
• C++
• C
• Java
• C#
• Ada
One needs to decide about the target language before start of a project, consequently Rhapsody starts in
language dependent variants, Rhapsody in C++, Rhapsody in C, and so on. They differ a bit, but naturally the
differences are related to user defined code inside the model and not to UML model elements. They keep
identical in the different variants.
Naming conventions
Model element names in UML can be constructed using any characters including spaces. But Rhapsody is
different in this respect. As rule of thumb use this recommendation:
#1:
Use the same naming conventions as you use
inside the target language.
#2:
Use spaces only in diagram names.
2
Willert Software Toolsⓒ
Basics
The GUI
IBM® Rational® Rhapsody® (from now on named as Rhapsody) allows building up a model inside a workspace.
When starting with the model, one has to open or to create a Rhapsody project. The GUI consists of
• a browser
• a diagram pane
• an output pane
• a drawing toolbox
• a feature window
The browser contains all model elements, this is the full view into the whole model. One can show model
elements on diagrams, where they can be understood easier and quicker than inside the browser. Usually they
appear in different layouts, depending on their purpose. There are layouts for overviews or layouts for details.
Consequently you can place a model element onto several diagrams, each having different context and
purpose, some showing details, some not.
The drawing toolbox contains all those model elements that can be shown on diagrams. The toolbox is
context sensitive, i.e. if the current diagram is a Class Diagram, the model elements of Class Diagrams are inside
the box. If the current diagram is a Sequence Diagram, only model elements of Sequence Diagrams are
available.
The output pane shows messages for different tasks in the tool and is divided in different tabs, e.g. if you start a
search a new tab with the search results for your search string is created.
The feature window enables you to enter details for model elements, details that cannot be edited inside the
symbols on diagrams. The features window is also context sensitive, i.e. it shows the properties of the currently
selected model element. The window is a separate one, you can leave it open the whole time you work in
Rhapsody. One can also dock it into Rhapsody’s main window, just open the context menu of the title bar of
the features window and select the option “Enable Docking by Drag”.
Browser
Diagram pane
Output pane
3
Feature window
Drawing toolbox
Willert Software Toolsⓒ
Creation of model elements
Model elements can be created directly inside the browser as well as on diagrams or inside the features
window. Elements that already exist can be shown on diagrams with the usage of drag&drop from the browser.
Create inside browser: Select an entry in the
model browser, open the context menu with
the right mouse and select “Add New” then
the appropriate model element.
Create inside diagram: Click on the symbol in
the toolbox and click into the diagram.
Being in “Select Mode”: you can create only
one model element.
Being in “Stamp Mode”: every new click in the
diagram creates a model element until you
deactivate “Stamp Mode”.
Renaming of model elements
Model elements can be renamed anywhere in the browser or on a diagram. If a name is changed all references
to the definition will be updated automatically through the whole model.
Deleting model elements
There are 2 different ways to get rid of model elements: remove from a diagram and delete from the model.
The first variant removes only one symbol from one diagram, all other references stay at the place they have.
The second variant deletes the model element from the browser and all references from all diagrams and the
browser as well.
Rules of thumb:
#3:
Whenever you want to delete a model element
totally from your model, select it inside the
browser and use the “Del” key.
#4:
If you deleted something and the tool did not
ask you whether the deletion should take place,
you removed the symbol only from the diagram
and not from the model.
4
Willert Software Toolsⓒ
Model Browser
The Project
The upper most entry is the project name. All global project
settings are saved here. The appropriate project file in the file
system has the name “Project.rpy”.
The Component
This is Rhapsody’s component. You can have several components,
but only one of them is active. Herein you specify what is content
of a build process, e.g. which model parts are included, which
external libraries, etc.. Also a reverse engineering step should be
defined within an own component.
The Configuration
This defines the kind of a build process, it gives an answer to the
question “how is the build process done”. The configuration of
the code generation and the compilation and linking is made
here. One can use several configurations inside one component.
For example one configuration for a simulation, one for a release.
Only one configuration is active.
The Object Model Diagram
Rhapsody uses own diagrams. An Object Model Diagram (mostly
abbreviated with OMD) can be used instead of several UML
diagrams, usually for Class-, Object- and Component Diagrams. A
default diagram is created automatically below the project,
recommended is to show only the package structure at this
model level.
The Package
Here we see the structure of the model. Reminder UML: a
package is nothing else but a container for any other model
element. Recommended is to not use a name “Default”. The
content of a package is normally stored within an own file in the
file system, the name for the Default package is Default.sbs.
The Profile
A special kind of package. Normally used to store properties or
stereotypes. The screenshot shows the official Testing Profile from
the OMG.
The Category
This is an additional concept in Rhapsody to structure the model.
Examples for categories in the screenshots are “Components“,
“Object Model Diagrams”, Packages” and “Profiles”.
5
Willert Software Toolsⓒ
Modeling in Diagrams
A first step is to have a diagram. Select the “owner” package for the intended diagram in the model browser
and create the diagram by using the context menu “Add New” and the sub-menu “Diagrams”. Second step is
to place symbols onto the diagram using the “Drawing” toolbox as described previously. Now some details:
The “Layout” Toolbox
If you have several objects in different size and different alignments and want to change that, use the layout
toolbox. It gets activated only if you have several symbols selected.
align top
make same size
(the last selected symbol is the master)
Display Options
Some more layout relevant options are managed from the window “Display Options”; it gets activated from the
context menu of a symbol inside a diagram. One can for example choose, whether the name shall be shown as
relative name or as a “Full Path”, i.e. also the whole structure where the element is located. If you select a class
you can also choose whether ports and interfaces of the ports shall be visible, or which compartments shall be
shown. The display options are set for one single symbol only.
Images
If your model or parts of it is intended to be shown to non UML users, you can associate an image to a
symbol. Similar to the display options, select one symbol in a diagram and open the context menu. You’ll find an
entry “Associate Image...”. Example:
6
Willert Software Toolsⓒ
The Features Window
The features window enables you to enter details for model elements, details that cannot be edited elsewhere
in the browser or inside the symbols on diagrams. The features window is context sensitive, i.e. it shows the
properties of the currently selected model element. This is the default, but one can “pin” the window, in that
case the window is no longer context sensitive, i.e. it does not change the window content if you select another
model element.
The window is a separate one, you can leave it open the whole time you work in Rhapsody. One can also dock
it into Rhapsody’s main window, just open the context menu of the title bar of the features window and select
the option “Enable Docking by Drag”; then drag it into another Rhapsody window.
Example to specify details or create model elements inside the features window, double-click on a class and you
see:
Now activate the “Attributes” tab and you are able to create attributes there just by clicking on the “New”
entry.
Others
Navigation
Navigating an element between the browser and the appropriate symbol on diagrams is possible. Try the
context menu entry “Navigate”, then one of the entries in the sub-menu; or use “Ctrl-l” to locate an element
inside the browser.
How is the model saved
As mentioned earlier, Rhapsody stores all model related information in files in the file system. Per default one
file for the project and one directory for all packages and components. The project file has the name
“<project>.rpy”, the folder “<project>_rpy”, the packages have the suffix “.sbs” and the components the suffix
“.cmd”. When you create new packages or components, new files are generated as well, this is natural. But if
you delete a package or component, the appropriate file is not deleted; take as rule of thumb: Rhapsody does
not delete files in the file system. Some more files can be found inside the folder that contains “<project>”.rpy
but they do not contain model elements or diagrams. If you delete them, you do not corrupt the model.
Controlled Files
Files containing not model elements but pictures, word- or excel data, that are somehow important to a UML
model can be included into the project as “controlled file”. The file has to be stored somewhere below the
“<project>_rpy folder. The content can not be read from Rhapsody, but Rhapsody invokes the appropriate
tool instead.
7
Willert Software Toolsⓒ
Exercise
Here is a small exercise to get familiar with the GUI; create a model that counts down from 10 to 0. The
model will contain one class only, but attributes, operations and a state machine diagram are included. When
the model is finished it will first run in an animation mode and after that as a Windows executable.
Step 1: create a Rhapsody project
Use the Windows start menu, and start the Rhapsody Developer, use C++ as language. From the “File” menu
choose “New” and enter an appropriate windows file folder and the project name. Project type and project
setting shouldn’t be changed.
The tool asks you now for allowance to create a new folder “CountDown” inside the folder “C:\work”. Just
accept. Get familiar with the model created so far.
Which model elements and diagrams are created automatically?
Consider: Rhapsody uses an Object Model Diagram as an “overall” diagram for structural elements.
8
Willert Software Toolsⓒ
Step 2: create the class with attributes and operations
Click on the “Class” symbol in the drawing box and place it onto the object model diagram, name the class
“CountDown”. Alternatively create a Class Diagram and create the class “CountDown” there. To implement
the behavior we need an attribute (“counter”) two operations (“printNr” and “printStr”) and a State Machine
Diagram. The attributes and the 2 operations should be created by using the features window of the class
“CountDown”. Open it with a double click on the class symbol of “CountDown” on the diagram or on the
model element “CountDown” in the browser, select the appropriate tabs “Attributes” / “Operations” and click
on the “New” entry there. Name the new elements as suggested above.
Then select the operation and click on the “Invoke Feature Dialog”, this opens a second feature window. It
should be used to enter argument and implementation for the operations, see screenshot as a suggestion for
operation “printStr”, “printNr” should have a similar implementation but with a number as argument.
9
Willert Software Toolsⓒ
Step 3: create a State Machine Diagram
Consider: in Rhapsody we use the name “Statechart” instead.
To create that diagram select the class “CountDown”,
a) then either right mouse click to open the context menu, then “Add New”->”Diagrams”->”Statechart”, or
b) use the “Open Statechart” button, see screenshot below.
Use the “Drawing Toolbox” to specify now the behavior, pick appropriate symbols in the toolbox and place
them onto the diagram. Reminder: to enter details use the features window, it helps also to specify triggers,
guards or actions on transition lines.
Step 4: create an executable
Reminder: classes in UML specify resources, but when we want to get the model running we need to have
instances of classes. Create an object of the class “CountDown”, right click the class inside the browser to open
the context menu and choose “Make an Object”. The object will have a default name “itsCountDown”. Feel
free to rename it to a better name.
Step 4a: generate code
An executable is generated in different steps: first task is done from Rhapsody’s code generator, it generates
target code, as we chose Rhapsody in C++, we will get CPP and H files. This phase needs to be configured,
open the features window of the model element “DefaultComponent” and figure out which scope is set. Then
open the menu “Code”, then “Generate” and “DefaultConfig”. You’ll be asked whether Rhapsody may create
the target directory “....\CountDown\DefaultComponent\DefaultConfig”. Agree, open a file explorer to figure
out which files are generated.
Step 4b: compile and link
Rhapsody does NOT include a compiler, it is expected that a compiler is already installed, ideally the compiler is
installed before the Rhapsody installation. In that case a “connection” between compiler and Rhapsody is
installed automatically. If not, interrupt the exercise here and repair the installation.
Continuation:
As the “DefaultComponent” in the model specifies only the scope of the code generation, it’s also necessary to
specify how the compilation is done. Open the features window of the model element “DefaultConfiguration”
below the “DefaultComponent”, and switch to the tab “Settings”. Choose the correct compiler in the list box
“Environment”. Afterwards open the “Initialization” tab and specify the initial instance.
10
Toolsⓒ
Willert Software
Step 5: run the executable
Very simple: press the “Generate/Make/Run” button:
The Result:
Step 6: simulate the behavior
The state machine isn’t very complicated, but in normal cases you need to walk manually through the
specification, this can be done in Rhapsody’s animation mode. Open the features window of the configuration
of the code generation (reminder: below the “DefaultComponent” we have the “DefaultConfig”) and choose
“Animation” in the list box “Instrumentation Mode”. Press the “Generate/Make/Run” button and wait until the
executable starts. Minimize the command box and observe a new toolbox inside Rhapsody’s GUI:
Press the “Go Step” button four or five times. If the state machine diagram of the object is not opened
automatically, open the “Tools” menu and choose “Animated Statechart”: result shall be:
Now:
Play with the “Animation Toolbox”
11
Toolsⓒ
Willert Software
Dishwasher
The second example gets a bit more complex. Create the state machine of a dishwasher. Use simply the
principle of “time goes by” to simulate the washing, rinsing and drying process, i.e. a timer expires after 10
seconds means the washing is done. Consider that one can usually open and close the door of the machine
during the execution phase without causing a stop and restart of the process. Implement also different
programs, for example a normal mode and a quick wash mode. Use regions in state machines for this purpose.
The following picture of the state machine should be guidance enough:
Needed Attributes:
washingTime, rinsingTime, dryingTime, cycles
Needed Operations:
setup(), isWashed(), isRinsed(), isDried()
How to differentiate between normal mode and quick mode:
The attributes for simulating the duration of the different phases are initialized differently inside the operation
setup(). For example, if the state machine is inside state normal the attribute “washingTime” is set to 8, if it is in
the state quick, washingTime is set to 5.
Similar to the first example:
Create an executable, and run it inside a simulation.
12
Toolsⓒ
Willert Software
Dishwasher System
The third example gets a bit more complex. Now we do no longer have a single class, but there is a
collaboration of several classes, as this is the case in every normal model. The intention here is to get you
familiar with Rhapsody’s way to model the collaboration.
We will have a class “motor” with just 2 operations “on” and “off ”. And a class “panel” that allows to start and
stop the washing, to simulate the opening and closing of dishwasher’s door.
Access from class dishwasher to class motor is modeled with an association, the communication between panel
and dishwasher with ports and interfaces.
Here are some hints:
A class diagram to define the resources:
A composite structure diagram to define the system (including the root class “DishwasherBuilder”)
An example of the state machine for the class “FrontPanel”:
and the operation processKey():
13
Toolsⓒ
Willert Software
Dishwasher - Testing with Webify
One more good feature of Rhapsody is its ability to execute the model in an advanced mode. The code
generator of Rhapsody generates some additional code into the executable to enable the collaboration
between a web page and the executable. That allows the user to visualize and modify attributes, or to send
events via the web page. Some prerequisites are necessary:
• Set the stereotype “Web Managed” to all model elements that should be on the web page:
• Select Web Enabling in the configuration.
• Press the button GMR
• Press the botton GO
in the execution toolbox
after the executable started
• Open http://localhost
inside a web browser
and play with the web page
14
Toolsⓒ
Willert Software
Dishwasher - Testing with Panel Diagram
One more good feature of Rhapsody is its ability to execute the model in an advanced mode. The code
generator of Rhapsody generates some additional code into the executable to enable the collaboration
between the executable and a special diagram: Panel Diagram.
See an example:
There are a lot of widgets possible inside such a diagram, all of them can be found inside the drawing toolbox
of a panel diagram. When you are satisfied with the layout of your diagram, you have to take care of
• the name of a widget, e.g. “Close”, use the features window for that
• the “binding” to a special model element, use the features window for that.
Now: play with the Panel Diagram, once you started the executable and don’t forget to press the GO button.
15
Toolsⓒ
Willert Software
Product:
IBM® RATIONAL® RHAPSODY®
START-UP TRAINING
Author:
WOLFGANG SONNTAG
Editor:
WILLERT SOFTWARE TOOLS
GMBH
Hannoversche Straße 21
DE - 31675 Bückeburg
Phone: +49 5722 9678 - 60
[email protected]
www.willert.de!
16
Toolsⓒ
Willert Software