UML Tutorial
UML Tutorial
UML Tutorial
(With Example)
Patni Internal 15
UML Tutorial (With Example)
DOCUMENT CONTROL
Document History :
What is UML?
Patni Internal 15
UML Tutorial (With Example)
Goals of UML
The primary goals in the design of the UML were:
History of UML
Patni Internal 15
UML Tutorial (With Example)
The development of UML began in late 1994 when Grady Booch and Jim
Rumbaugh of Rational Software Corporation began their work on unifying the
Booch and OMT (Object Modeling Technique) methods. In the Fall of 1995, Ivar
Jacobson and his Objectory company joined Rational and this unification effort,
merging in the OOSE (Object-Oriented Software Engineering) method.1
As the primary authors of the Booch, OMT, and OOSE methods, Grady Booch,
Jim Rumbaugh, and Ivar Jacobson were motivated to create a unified modeling
language for three reasons. First, these methods were already evolving toward
each other independently. It made sense to continue that evolution together
rather than apart, eliminating the potential for any unnecessary and gratuitous
differences that would further confuse users. Second, by unifying the semantics
and notation, they could bring some stability to the object-oriented
marketplace, allowing projects to settle on one mature modeling language and
letting tool builders focus on delivering more useful features. Third, they
expected that their collaboration would yield improvements in all three earlier
methods, helping them to capture lessons learned and to address problems that
none of their methods previously handled well.1
The efforts of Booch, Rumbaugh, and Jacobson resulted in the release of the
UML 0.9 and 0.91 documents in June and October of 1996. During 1996, the
UML authors invited and received feedback from the general community. They
incorporated this feedback, but it was clear that additional focused attention
was still required.1
While Rational was bringing UML together, efforts were being made on
achieving the broader goal of an industry standard modeling language. In early
1995, Ivar Jacobson (then Chief Technology Officer of Objectory) and Richard
Soley (then Chief Technology Officer of OMG) decided to push harder to achieve
standardization in the methods marketplace. In June 1995, an OMG-hosted
meeting of all major methodologists (or their representatives) resulted in the
first worldwide agreement to seek methodology standards, under the aegis of
the OMG process.1
During 1996, it became clear that several organizations saw UML as strategic to
their business. A Request for Proposal (RFP) issued by the Object Management
Group (OMG) provided the catalyst for these organizations to join forces around
producing a joint RFP response. Rational established the UML Partners
consortium with several organizations willing to dedicate resources to work
toward a strong UML 1.0 definition. Those contributing most to the UML 1.0
definition included: Digital Equipment Corp., HP, i-Logix, IntelliCorp, IBM, ICON
Computing, MCI Systemhouse, Microsoft, Oracle, Rational Software, TI, and
Unisys. This collaboration produced UML 1.0, a modeling language that was
well defined, expressive, powerful, and generally applicable. This was
submitted to the OMG in January 1997 as an initial RFP response.1
Patni Internal 15
UML Tutorial (With Example)
incorporate contributions from the new partners. It was submitted to the OMG
for their consideration and adopted in the fall of 1997.
Each UML diagram is designed to let developers and customers view a software
system from a different perspective and in varying degrees of abstraction. UML
diagrams commonly created in visual modeling tools include:1
Use Case Diagram displays the relationship among actors and use cases.1
Class Diagram models class structure and contents using design elements such
as classes, packages and objects. It also displays relationships such as
containment, inheritance, associations and others. 1
Interaction Diagrams
Activity Diagram displays a special state diagram where most of the states are
action states and most of the transitions are triggered by completion of the
actions in the source states. This diagram focuses on flows driven by internal
processing.1
Physical Diagrams
Patni Internal 15
UML Tutorial (With Example)
use cases. The two main components of a use case diagram are use cases and
actors.
An actor is represents a user or another system that will interact with the
system you are modeling. A use case is an external view of the system that
represents some action the user might perform in order to complete a task.
Patni Internal 15
UML Tutorial (With Example)
This example shows the customer as an actor because the customer is using the
ordering system. The diagram takes the simple steps listed above and shows
them as actions the customer might perform. The salesperson could also be
included in this use case diagram because the salesperson is also interacting
with the ordering system.
From this simple diagram the requirements of the ordering system can easily be
derived. The system will need to be able to perform actions for all of the use
cases listed. As the project progresses other use cases might appear. The
customer might have a need to add an item to an order that has already been
placed. This diagram can easily be expanded until a complete description of
the ordering system is derived capturing all of the requirements that the
system will need to perform.
Class Diagrams
Class diagrams are widely used to describe the types of objects in a system and
their relationships. Class diagrams model class structure and contents using
design elements such as classes, packages and objects. 2 Class diagrams
describe three different perspectives when designing a system, conceptual,
specification, and implementation.1 These perspectives become evident as
the diagram is created and help solidify the design. This example is only meant
Patni Internal 15
UML Tutorial (With Example)
as an introduction to the UML and class diagrams. If you would like to learn
more see the Resources page for more detailed resources on UML.
Patni Internal 15
UML Tutorial (With Example)
In this example the classes Corporate Customer and Personal Customer have
some similarities such as name and address, but each class has some of its own
attributes and operations. The class Customer is a general form of both the
Corporate Customer and Personal Customer classes.1 This allows the designers
to just use the Customer class for modules and do not require in-depth
representation of each type of customer.
Before drawing a class diagram consider the three different perspectives of the
system the diagram will present; conceptual, specification, and
implementation. Try not to focus on one perspective and try seeing how they
all work together.
Patni Internal 15
UML Tutorial (With Example)
When designing classes consider what attributes and operations it will have.
Then try to determine how instances of the classes will interact with each
other. These are the very first steps of many in developing a class diagram.
However, using just these basic techniques one can develop a complete view of
the software system.
This example is only meant as an introduction to the UML and use cases. If you
would like to learn more see the Resources page for more detailed resources on
UML.
Interaction Diagrams
Interaction diagrams model the behavior of use cases by describing the way
groups of objects interact to complete the task. The two kinds of interaction
diagrams are sequence and collaboration diagrams. This example is only meant
as an introduction to the UML and interaction diagrams. If you would like to
learn more see the Resources page for a list of more detailed resources on UML.
Patni Internal 15
UML Tutorial (With Example)
object is doing for several use cases use a state diagram. To see a
particular behavior over many use cases or threads use an activity
diagrams. 1
Sequence diagrams:
Below is a slightly more complex example. The light blue vertical rectangles the
objects activation while the green vertical dashed lines represent the life of the
object. The green vertical rectangles represent when a particular object has
control. The represents when the object is destroyed. This diagram also
shows conditions for messages to be sent to other object. The condition is listed
between brackets next to the message. For example, a [condition] has to be met
before the object of class 2 can send a message() to the object of class 3.
Patni Internal 15
UML Tutorial (With Example)
The next diagram shows the beginning of a sequence diagram for placing an
order. The object an Order Entry Window is created and sends a message to an
Order object to prepare the order. Notice the names of the objects are followed
by a colon. The names of the classes the objects belong to do not have to be
listed. However the colon is required to denote that it is the name of an object
following the objectName:className naming system.
Next the Order object checks to see if the item is in stock and if the [InStock]
condition is met it sends a message to create a new Delivery Item object.
The next diagrams add another conditional message to the Order object. If the
item is [OutOfStock] it sends a message back to the Order Entry Window object
stating that the object is out of stack.
Patni Internal 15
UML Tutorial (With Example)
This simple diagram shows the sequence that messages are passed between
objects to complete a use case for ordering an item.
Collaboration diagrams:
Collaboration diagrams are also relatively easy to draw. They show the
relationship between objects and the order of messages passed between them.
The objects are listed as icons and arrows indicate the messages being passed
between them. The numbers next to the messages are called sequence
numbers. As the name suggests, they show the sequence of the messages as
they are passed between the objects. There are many acceptable sequence
numbering schemes in UML. A simple 1, 2, 3... Format can be used, as the
example below shows, or for more detailed and complex diagrams a 1, 1.1
,1.2, 1.2.1... scheme can be used.
The example below shows a simple collaboration diagram for the placing an
order use case. This time the names of the objects appear after the colon,
such as :Order Entry Window following the objectName:className naming
convention. This time the class name is shown to demonstrate that all of
objects of that class will behave the same way.
Patni Internal 15
UML Tutorial (With Example)
State Diagrams
State diagrams are used to describe the behavior of a system. State diagrams
describe all of the possible states of an object as events occur. Each diagram
usually represents objects of a single class and track the different states of its
objects through the system.
All state diagrams being with an initial state of the object. This is the state of
the object when it is created. After the initial state the object begins changing
Patni Internal 15
UML Tutorial (With Example)
states. Conditions based on the activities can determine what the next state
the object transitions to.
State diagrams can also show a super-state for the object. A super-state is used
when many transitions lead to the certain state. Instead of showing all of the
transitions from each state to the redundant state a super-state can be used to
Patni Internal 15
UML Tutorial (With Example)
show that all of the states inside of the super-state can transition to the
redundant state. This helps make the state diagram easier to read.
The diagram below shows a super-state. Both the Checking and dispatching
states can transition into the Canceled state, so a transition is shown from a
super-state named Active to the state Cancel. By contrast, the state
Dispatching can only transition to the Delivered state, so we show an arrow
only from the Dispatching state to the Delivered state.
Activity Diagrams
Patni Internal 15
UML Tutorial (With Example)
However, activity diagrams should not take the place of interaction diagrams
and state diagrams. Activity diagrams do not give detail about how objects
behave or how objects collaborate. 1
Below is a possible activity diagram for processing an order. The diagram shows
the flow of actions in the system's workflow. Once the order is received the
Patni Internal 15
UML Tutorial (With Example)
activities split into two parallel sets of activities. One side fills and sends the
order while the other handles the billing. On the Fill Order side, the method of
delivery is decided conditionally. Depending on the condition either the
Overnight Delivery activity or the Regular Delivery activity is performed.
Finally the parallel activities combine to close the order.
Physical Diagrams
Patni Internal 15
UML Tutorial (With Example)
Patni Internal 15
UML Tutorial (With Example)
UML By Example
Table of Contents
1 Elevator Problem
2 Unified Modeling Language
3 Analysis
3.1 Use Case Diagram
3.2 Class Diagram
3.3 State Diagram
4 Designs
4.1 Sequence Diagram
4.2 Collaboration Diagram
5 Detail Design
5.1 Detail Class Diagram
5.2 Detail Operation Description
5.3 Pseudo-Code
Patni Internal 15
UML Tutorial (With Example)
0. Introductions
The aim of this tutorial is to show how to use UML in "real" software
development environment.
1. Elevator Problem
o Each elevator has a set of m buttons, one for each floor. These
illuminate when pressed and cause the elevator to visit the
corresponding floor. The illumination is canceled when the
elevator visits the corresponding floor.
o Each floor, except the first floor and top floor has two buttons,
one to request and up-elevator and one to request a down-
elevator. These buttons illuminate when pressed. The illumination
is canceled when an elevator visits the floor and then moves in
the desired direction.
3. Analysis
3.1. Use case diagram
Patni Internal 15
UML Tutorial (With Example)
Use_Case_Diagram:
Elevator basic scenario that can be extracted from Use Case Diagram:
Patni Internal 15
UML Tutorial (With Example)
Class
diagram:
4. Design
The design phase should produce the detailed class diagrams,
collaboration diagrams, sequence diagrams, state diagrams, and activity
diagram. However, the elevator problem is too simple for an activity
diagram. Thus, we are not using an activity diagram for the elevator
problem.
4.1. Sequence Diagram
A sequence diagram and collaboration diagram conveys similar
information but expressed in different ways. A Sequence diagram shows
the explicit sequence of messages suitable for modeling a real-time
system, whereas a collobration diagram shows the relationships between
objects.
Sequence Diagrams:
Patni Internal 15
UML Tutorial (With Example)
Sequence
Diagram for Serving Door Button
Patni Internal 15
UML Tutorial (With Example)
Collabration diagrams:
5. Detail Design
Patni Internal 15
UML Tutorial (With Example)
5.3.Pseudo-Code
Patni Internal 15
UML Tutorial (With Example)
button::illuminate;
update request list;
}
elseif
elevator is moving up
{
if there is no request to stop at floor f
Elevator::move one floor up;
else
}
Patni Internal 15