Rationalrosenotes
Rationalrosenotes
UML
Michael M Werner
2003 All rights reserved
12/2/2014
Introduction
Unified Modeling Language (UML) was created in 1995 by merging diagramming
conventions used by three software development methodologies: OMT by James
Rumbaugh, Objectory by Ivar Jacobson and the Booch Method by Grady Booch. Prior to
this time, these three amigos, along with about a dozen other practitioners had promoted
competing methodologies for systematic software development, each with its own system
of diagramming conventions. The methodologies followed a kind of cookbook style of
pushing a software project through a succession of life cycle stages, culminating with a
delivered and documented application. One goal of UML was to reduce the proliferation
of diagramming techniques by standardizing on a common modeling language, thus
facilitating communication between developers. It achieved that goal in 1997 when the
(international) Object Management Group (OMG) adopted it as a standard.
Some critics consider that UML is a bloated diagramming language written by a
committee. That said, I consider it to be the best means available today for documenting
object-oriented software development. It has been and is becoming increasingly used in
industry and academia.
It should be stressed that UML is not a methodology, rather it is a language for expressing
software models. Conceivably, it can be used with various software methodologies.
However, separately from the UML, the three amigos have developed the Rational
Unified Process, a methodology that is use case driven, and carried out using UML
models.
Rational Rose is a Computer Aided Software Engineering (CASE) tool developed by the
Rational Corporation under the direction of Booch, Jacobson and Rumbaugh to support
software development using UML. Rational Rose is necessarily complex owing to its
mission of fully supporting UML. In addition, Rational Rose has numerous language
extensions to Ada, C++, VB, Java, J2EE, etc. Rational Rose supports forward and
reverse engineering to and from these languages. On the other hand, Rational Rose does
not support some traditional design techniques as data flow diagrams and CRC cards,
since these are not part of UML.
Because Rational Rose has so many capabilities it is a daunting task to master it.
Fortunately, a lot can be done using just a small subset of these capabilities. These notes
are designed to introduce novice developers into making productive use of such a subset.
They reflect the authors bias towards developing software and should not be taken as the
last word on the subject.
12/2/2014
1.
2.
3.
4.
0. Project Initiation
The project initiation phase involves identifying a problem that need a software solution,
investigating to see if an adequate solution is already available for purchase, if not,
working up an informal proposal outlining new software to be built and making the case
that the expected benefits justify the cost. Rational rose need not be involved in this
phase.
1.
Requirements
The requirements phase involves eliciting requirements from the client and presenting
them in a formal contractual document that will later serve as the basis for acceptance of
the finished project. Getting the requirements right is key to the success of the project.
However, the software developers are usually not expert on the clients business
environment, nor are the clients necessarily good at expressing what their real
requirements are. The developers need to work with the clients to determine the real
requirements.
Use Case Diagram - The best tool I know of for talking about requirements is the
use case diagram, developed by Jacobson. The diagrams and the use case
technique are so simple that clients instantly relate to them and will readily
volunteer usual and exceptional scenarios to go along with each use case. The use
cases are recorded in the use case view of rational rose.
Some other diagrams strictly speaking belong to the design phase, but may also be useful
in the requirements phase. They are constructed in Rational Roses Logical View.
12/2/2014
Class Diagram As part of the requirements process entity classes are identified
and described in terms of attributes, operations and associations using the UML
class diagram. A class is an entity class if it forms part of the clients business
model. So, for example, if the client is running a hospital, possible entity classes
are: Patient, Doctor, Nurse, Therapist, Bed, Treatment, Diagnosis, etc. On the
other hand, classes such as Form, Canvas, Button, Socket, etc. are not entity
classes. They are classes needed to implement the solution, but are not
meaningful in describing the clients business, hence not part of the requirements
phase.
Another way to look at entity classes is from a database point of view. The entity
classes are usually the persistent ones, i.e. they describe the objects, which the
system will permanently track in a database.
2.1
Architectural Design
12/2/2014
2.2
Detail Design
Statechart Diagram (Logical View) The state of an object is the current set of
values of all its attributes (including inherited ones). Objects may change state in
response to messages received. The statechart diagram shows all the states,
transitions between states labeled by the messages, which cause them, and guards
on transitions.
Activity Diagram (Logical View) These diagrams are similar to the familiar
flowcharts. They show activities (processes) and the flow of control and data
between activities.
Together the sequence, statechart and activity diagrams form the dynamic model of the
system. In general, the system is at rest until an actor initiates a use case by requesting a
system function. This causes a flurry of messages and state changes as predicted by the
dynamic model.
3.
Implementation
In the implementation phase the detailed design is actually carried out in program code
using a target language. Data definition language is written to create and populate the
12/2/2014
database tables and grant role-based privileges. Reports and interactive forms are
written, as well as help files and exception handling routines.
The implementation phase is characterized by testing, unit tests to see if individual
modules work correctly, integration tests to ensure that the modules work together
properly to carry out the use cases. Tested modules are deployed to the target hardware
and retested on site. Finally, acceptance testing verifies that the system carries out its
various functions correctly, i.e. according to their specification in the requirements
document.
Rational Rose provides extensive support for implementation:
4.
Model checking.
Forward code generation (from model to source code) in a variety of target
languages.
Maintenance
12/2/2014
12/2/2014
Choose a default language. This is the language you plan to develop in. I chose J2EE,
since I plan to make a Java application. This is the browser window. You will create a
model by adding various artifacts such as use cases, diagrams, classes, etc. to it. All
artifacts are accessible from the browser whether they are shown in diagrams or not.
Note that the browser window also shows the four rational rose views, discussed earlier.
The model properties are the settings for generating code in the various target languages.
You can double click the icon in the browser window to change these, or select Model
Properties from the Tools menu.
12/2/2014
Create a new package and name it Circulation. Add actors and use cases to the
circulation package by right clicking on the package name and choosing new. Each actor
and use case should be described in the documentation window, usually located in the
lower left of your screen. Add a new use case diagram to the Circulation package, name
it Main, and drag actors and use cases onto it. Choose the unidirectional association tool
and drag from the actor to the use case. Now create a use case diagram for the library
circulation system.
Start with typical usages such as borrowing and returning a book. Identify the actors
involved, for example library cardholders and circulation librarians. Think of the
different titles we use for librarians and whether their job descriptions include using the
library circulation system in some way. Dont neglect boundary conditions. These
include startup, shutdown and handling exceptions. How will new books be entered into
the system and old ones removed? Usually an acquisitions librarian is in charge and
will have use cases for acquiring and disposing of books. Similarly, think of how library
users will apply for and be issued library cards, and possibly lose borrowing privileges if
they fail to comply with library rules. Here is a sample use case diagram.
12/2/2014
Cardholder
UpdateProfile
Borrow
Reserve
Renew
Login
Return
PayFee
Circulation Librarian
Acquisitions
Librarian
AcquireBook
GetReports
DisposeBook
FineCardHolder ApproveLibraryCard
Remind
Public User
SuspendLibraryCard
ApplyForCard
BrowseTitles
No code will be generated from the use cases so dont agonize over getting them exactly
right. UML provides for <<include>> and <<extend>> associations between use cases.
The << >> notation stands for a UML stereotype. <<include>> is a standard
stereotype to indicate that one use case, say Login, is included as a common part of other
10
12/2/2014
The dotted arrows are used for dependencies between use cases. Double clicking on an
arrow brings up its specification window. You can choose a standard stereotype or type
in a new one. This is part of UMLs extensibility feature.
Bear in mind that the main purpose of use cases is to be able to review them with your
client so as to get the requirements right. Later we will see that they play a role in
discovering domain classes and in drawing class and sequence diagrams.
Scenarios
A scenario is basically a flow of events that occur when a use case is carried out. The
scenario should have entry and exit conditions, plus a list of steps that are followed.
Associated with each use case is the usual scenario if everything goes right and several
exceptional scenarios followed if something goes wrong. Rational Rose does not supply
specific support for storing scenarios. There are thus two choices: (1) Write the scenarios
in the documentation window for the use case, or (2) attach a file to the use case
containing the scenarios. Keep the language simple so that your clients can understand
and work with you on the scenarios. Here is an example of writing the scenarios for the
borrow use case in the documentation window.
11
12/2/2014
By the way, it is time to save your model if you havent already done so. Choose Save As
from the file menu, and specify a name and location. This will also give a name to the
model.
12
12/2/2014
Add classes to the Circulation package by right clicking on the package name and
choosing new. Add a Class Diagram to the Circulation package, and label it Main,
Add a class for each entity object in the library circulation system.
Add attributes to each class by right-clicking on the class and pressing new. You
can follow the attribute name by a colon and a type as in: balance:double.
Alternatively, you can open the specification for the attribute to assign a Java type
to it. Although the Type field is grayed, you can click on the button and bring
up the Select a type window.
13
12/2/2014
Add operations. Open the specification for each operation to add parameters to it.
Add associations between classes. Open the specification for each association. It
is important to add multiplicities and role names for each association using the
tabs entitled Role A detail and Role B detail. The role names will be used in
code generation.
I created the following class diagram for the library circulation system.
14
12/2/2014
Person
username : String
password : String
name : String
Reservation
reserveDate : java.sql.Date
Reservation()
+reservations
+reserver
Cardholder
accountBalance : double 1
0..n
0..n
+reservation
+title
Librarian
borrowBook()
returnBook()
reserve()
Cardholder()
+borrower1
Title()
adjustAvailable()
+title isAvailable()
borrows
+loan
0..n
Loan
borrowDate : java.sql.Date
returnDate : java.sql.Date +loan
loanNumber : int
0..n
Loan()
returnBook()
Title
isdn : String
bookTitle : String
author : String
copiesAvailable : int
copy of
0..n
Book
copyNum : int
+book
1
+book
Book()
borrow(loan : Loan)
0..n
+loancontrols
+controller 1
ReturnControl
LoanControl
recordReturn()
opname()
name
recordBorrow(isdn : String, copy : int) : int
reserve(isdn : String) : int
15
12/2/2014
: Cardholder
: Cardholder
: LoanControl
: Loan
: Title
: Book
borrowBook(String, int)
recordBorrow(String, int)
Loan( String, int)
adjustAvailable()
borrow(Loan)
Receipt
Use Case
Diagram:
Circulation / Main
Class Diagram:
Circulation / Main
16
12/2/2014
OnShelf
borrow
OnLoan
return
Waiting
Shelving
Books in poor
condition are placed
in a discard pile.
Discard
17
12/2/2014
The only change I made on this screen was to change PropertyType to Simple. This is a
bean property. Simple means that get and set methods are generated for each attribute. I
made the same change for the Role type. Recall that the role names you specified in the
class diagram are used as field names in the generated code. (Assuming the association
ending was marked Navigable). When the role has multiplicity 0..n the type of the field
is a container. By default it is an array of the target type, but I changed the Container
Type to Vector.
18
12/2/2014
19
12/2/2014
The persistent classes will be converted into database tables. Each such table will need a
primary key. To enable joins the primary key field in one table may appear as a foreign
key in one or more related tables.
There are two approaches:
1)
2)
Allow the data modeler to generate a new integer-valued primary key id for the
table. Although these auto-generated ids are not meaningful to end-users, they do
save space and make for fast joins.
To designate an attribute to be part of the primary key, right-click on the attribute in the
browser, select Data Modeler, part of Object Identity.
You now need to set up a database component. Right-click on the Component View icon,
select Data Modeler | New | Database.
20
12/2/2014
Next you need to choose a database language for the database. Double-click on the diskshaped icon (probably named DB_!) to open its specification, and select the target
DBMS.
Next, create a schema. Right-click the Logical View icon, select Data Modeler | new |
Schema. A Schemas package and under it a schema named S_0 are created.
Open its specification and rename it to Circulation. Choose DB1 as its database.
Next, transform the Circulation package in the logical view to a data model. Right-click
the package, select Data Modeler | Transform to Data Model. In the dialog box, select the
schema and target database.
21
12/2/2014
Right-click on the Circulation schema in the browser, select Data Modeler | New | Data
Model Diagram. Rename the diagram to Main. Open it up and drag all the tables into it.
Drag them around to improve readability. You get something like:
22
12/2/2014
T_Reservation
reserveDate : SMALLINT
T_Reservation_ID : INT
T_Title_ID : INT
T_Person_ID : INT
<<Non-Identifying>>
0..*
<<PK>> PK_T_Reservation26()
<<Non-Identifying>>
<<FK>> FK_T_Reservation28()
<<FK>> FK_T_Reservation26()
0..* <<Index>> TC_T_Reservation308()
1
<<PK>> PK_T_Title24()
1
<<Non-Identifying>>
T_Cardholder
accountBalance : FLOAT(64, 0)
T_Person_ID : INT
<<PK>> PK_T_Cardholder27() <<Non-Identifying>>
1
<<FK>> FK_T_Cardholder29()
0..1
<<Identifying>>
0..*
1
T_Person
username : VARCHAR(255)
password : VARCHAR(255)
name : VARCHAR(255)
id : VARCHAR(255)
T_Person_ID : INT
T_Title
isbn : VARCHAR(255)
bookTitle : VARCHAR(255)
author : VARCHAR(255)
copiesAvailable : INT
T_Title_ID : INT
0..*
T_Loan
borrowDate : SMALLINT
returnDate : SMALLINT
loanNumber : INT
T_Loan_ID : INT
T_BookEJB_ID : INT
T_Person_ID : INT
T_BookEJB
<<Non-Identifying>>copyNum : INT
EJB_Context : SMALLINT
T_BookEJB_ID : INT
0..*
1 T_Title_ID : INT
<<PK>> PK_T_Loan25()
<<FK>> FK_T_Loan27()
<<FK>> FK_T_Loan24()
<<Index>> TC_T_Loan304()
<<PK>> PK_T_BookEJB23()
<<FK>> FK_T_BookEJB25()
<<Index>> TC_T_BookEJB306()
<<Identifying>>
1
0..1
<<PK>> PK_T_Person20()
T_Librarian
T_Person_ID : INT
<<PK>> PK_T_Librarian28()
<<FK>> FK_T_Librarian30()
23
12/2/2014
24
12/2/2014
25
12/2/2014
26
12/2/2014