L3 Uml
L3 Uml
L3 Uml
http://www-public.it-sudparis.eu/~gibson/Teaching/CSC7322/
UML – OO Modelling
http://www-public.it-sudparis.eu/~gibson/Teaching/CSC7322/L3-UML.pdf
UML is officially defined at the Object Management Group (OMG) by the UML
metamodel, a Meta-Object Facility metamodel (MOF).
UML is not restricted to modeling software. UML is also used for business process
modeling, systems engineering modeling, and representing organizational
structures.
UML has been a catalyst for the evolution of model-driven technologies, which
include Model Driven Development (MDD), Model Driven Engineering (MDE),
and Model Driven Architecture (MDA).
Rational Software Corporation hired James Rumbaugh from General Electric in 1994, the
company became the source for the two most popular object-oriented modeling approaches
of the day (OMT and Booch Method)
Together Rumbaugh and Booch attempted to reconcile their two approaches and started
work on a Unified Method.
Joined by Ivar Jacobson, the creator of the OOSE method, in 1995, after his company,
Objectory, was acquired by Rational.
The three methodologists were collectively referred to as the Three Amigos, since they
were well known to argue frequently with each other regarding methodological
preferences. (Jacobson: "What's the difference between a terrorist and a methodologist?
You can negotiate with a terrorist".)
The use case notation from Objectory and the component notation
from Booch were integrated with the rest of the notation, but the
semantic integration was relatively weak in UML 1.1
This was not really fixed until the UML 2.0 major revision.
The first part of UML 2.0, the Superstructure which describes the new diagrams
and modeling elements available, was adopted by the OMG in October 2004.
Other parts of UML 2, notably the infrastructure, the Object Constraint Language
(OCL) and the diagram interchange were ratified later.
The final UML 2.0 specification has been declared available and has been added
to OMG's formal specification library. The other parts of the UML specification,
the UML 2.0 infrastructure, the UML 2.0 Diagram Interchange, and UML 2.0
OCL specifications have been adopted.
UML version 2.1 revision is being developed, and should be available in the form
of an XMI 2.1 version of the UML 2.1 version. The corresponding XMI 2.1 file
will be made available from the OMG ADTF group.
Most of the commercially successful UML tools now support most of UML 2.0
It is very important to distinguish between the UML model and the set of diagrams of a
system.
In UML 2.0 there are 13 types of diagrams. To understand them, it is sometimes useful to
categorize them hierarchically:
Structure Diagrams emphasize what things must be in the system being modeled:
* Class diagram
* Component diagram
* Composite structure diagram
* Deployment diagram
* Object diagram
* Package diagram
Behavior Diagrams emphasize what must happen in the system being modeled:
* Activity diagram
* State Machine diagram
* Use case diagram
It is important to note that objects have a unique identity that remains unchanged throughout
their lifetimes. Ellie Foster is still the same person, even after she has changed her name to Ellie
Green.
Another important thing to note about objects is that they can play different roles in respect of
each other. They can play more than one role at the same time. For example, Ellie Foster is a wife
to Tom Green, a mother to Tom Green Jr and the author of Real Fast Food.
As well as describing objects, we can use UML to model types of objects, that is, sets of similar
objects that share the same characteristics. Types, or classes, as they are more commonly known in
object oriented software development, tell us what attribute values any instance of that type is
allowed to have, what roles objects of that type are allowed to play, and how many objects are
allowed to play the same role with respect to the same object.
We use the term multiplicity to refer to the number of objects that are allowed to play the same
role at the same time with respect to another object. For example, in the relationship mother->son,
the role of son can be played by zero or more objects of type Man at the same time with respect to
the same Woman, so the multiplicity of the role son is zero or more (or 0..*, or just *, in UML). In
the reverse, only one Woman can play the role of mother with respect to the same Man, so the
multiplicity of the role mother is exactly one (or simply 1 in UML).
Multiplicity (informally):
Every instance of a type has the characteristics defined by that type, and must
obey any rules that apply to it. If our type model tells us that every Man has
exactly one mother, for example, then an object of type Man with no mother, or
with two mothers, does not conform to its type.
So a type, or class, model tells us the rules about what instances of objects, their
attributes and the relationships between them are allowed. But quite often they
do not tell us all of the rules. Sometimes rules about types can be more complex
and subtle than, eg, a Man must have exactly one mother.
For example, how can we model the fact that a Woman cannot have a son who
is also the father of any of her other sons? We can use object models to illustrate
scenarios that might break these subtle rules.
{ son cannot be
father of any
other sons }
We can also combine UML with more formal models (in Event-B, eg)
2011: J Paul Gibson T&MSP: Software Engineering CSC7322/UML.23
Modelling Behaviour
For example, when the publisher reviews the draft of a book in development, it
could take the book into production design, but only if the publisher has approved
the draft.
Actions appear after that event and the guard - if there is one - for a transition.
Once we have identified the objects involved and their relationships, we must
now decide which object is taking responsibility for what action in the
execution of a process.
Sequence models describe how objects send messages to each other - through
well- defined interfaces - asking them to do some useful piece of work. Each
type of object has responsibility for providing a set of services, and the
interface for each type public face through which other objects can request
those services. In UML, we call those services operations.
A sequence model shows how, over time - and for a specific scenario (a
specific instance of a process - or a pathway through that process): the objects
involved use each others’ operations to get the job done.
Assigning these responsibilities is a key part in the object oriented thought
design process, and we will see how these models can be used in a well-defined
and rigorous object oriented development process.
Use case diagrams show the different classes of user and the goals they can
achieve using the system
Or ... Etc …?
Its worth nothing,though, that at this low level of abstraction the benefits of
modeling start to become questionable.
• By memorising:
Diagram by Diagram
• By analysing:
Case Studies
• By doing:
OO Analysis, Requirements and Design
• By using tools:
Validation, Verification, Code Generation, Reverse Engineering
Repeat
2. Electronic Voting
3. Telephone (POTS)
# protected attributes
- private attributes
Operations
+ public operations
# protected operations
- private operations
Templates
Generalisation
Associations
Associations can have a role that specifies the purpose of the association and can
be uni- or bidirectional (indicates if the two objects participating in the
relationship can send messages to the other, of if only one of them knows about
the other). Each end of the association also has a multiplicity value, which
dictates how many objects on this side of the association can relate to one object
on the other side.
Associations
Any two objects that are linked through an association are "married," just like
John and Mary. Such a marriage has a number of characteristics, which we call
the ABACUS rules. The characteristics that make up ABACUS (and compose
the acronym) are:
•Awareness: Both objects are aware of the fact that the relationship exists.
•Boolean existence: If the partners agree to a divorce, the relationship (in
UML called the link) is dissolved completely.
•Agreement: Both objects have to agree with the relationship; they need to
say "I do."
•Cascaded deletion: If one of the partners dies, the link is dissolved as well.
•USe of rolenames: An object may refer to its partner using the role name
provided with the association: "my husband" or "my wife."
<ordered> is
non-default
collection
The UML offers a choice in the type of collection used for an association end
with a multiplicity greater than one.
Set: Every element may be present in the collection only once. This is the
default collection type for association ends with a multiplicity larger
than one.
Ordered Set: A set in which the elements are ordered. There is an index
number for each element. Note that the elements are not sorted, that is,
an element with a lower index number is not in any way larger or
smaller than one with a higher index. An association end with this type
is indicated in the diagram by adding the marking <ordered>.
Bag: An element may be in the collection more than once. In the marriage
example this means that, for instance, Mary may be married to John
twice. Note that if one end of an association has this type, than the other
end must be either a bag or a sequence. The type is indicated in the
diagram by <bag>.
What are the effects of choosing a different collection type for an association
end?
Let us first stress that the ABACUS rules must hold, whatever type you
choose.
The type of the association end is relevant only when an element is added to
the relationship, and this is very important for the way associations are
implemented.
In the diagram for the group marriage (Figure 3) the end is marked "my
wives" as an ordered set.
This means that the implementer of the addWife operation in the class Man
that adds a woman to the ordered set must decide how to order the set of
wives.
Also, the implementer of addWife must make sure that the new wife is not
already present in the list of wives. The OrderedSet type does not allow this.
Implementing Associations
Aggregation
An Aggregation describes how the class that takes the role of the whole, is
composed (has) of other classes, which take the role of the parts.
For Aggregations, the class acting as the whole always has a multiplicity of one.
Composition
They exist only inside the whole, and if the whole is destroyed the parts die too.
Interfaces
Interfaces are abstract classes which means instances can not be directly
created of them. They can contain operations but no attributes. Classes can
inherit from interfaces (through a realisation association) and instances can
then be made of these classes.
Datatypes
Datatypes are primitives which are typically built into a programming
language. Common examples include integers and booleans. They can not
have relationships to classes but classes can have relationships to them.
Enums
Enums are a simple list of values. A typical example is an enum for days of
the week. The options of an enum are called Enum Literals. Like datatypes
they can not have relationships to classes but classes can have relationships to
them.
Packages
Packages represent a namespace in a programming language. In a diagram
they are used to represent parts of a system which contain more than one
class, maybe hundreds of classes.
Sequence Diagrams show the message exchange (i.e. method call) between
several Objects in a specific time-delimited situation.
Sequence Diagrams put special emphasis in the order and the times in which
the messages to the objects are sent.
The time axis is also vertical, increasing downwards, so that messages are sent
from one Object to another in the form of arrows with the operation name and
optionally the actual parameter values.
Lifelines
An example of the Student Lifelines are drawn as a box with a dashed line
descending from the center of the bottom edge
class used in a lifeline whose
instance name is freshman The lifeline's name is placed inside the box.
Messages
The first message of a sequence diagram always starts at the top and is
typically located on the left side of the diagram for readability.
Subsequent messages are then added to the diagram slightly lower then the
previous message.
The message/method name is placed above the arrowed line. The message
that is being sent to the receiving object represents an operation/method
that the receiving object's class implements.
Messages
In the example, the analyst object makes a call to the system object which is an
instance of the ReportingSystem class. The analyst object is calling the system
object's getAvailableReports method. The system object then calls the
getSecurityClearance method with the argument of userId on the secSystem
object, which is of the class type SecuritySystem.
Return Messages
Besides just showing message calls on the sequence diagram, the diagram includes
return messages.
These return messages are optional; a return message is drawn as a dotted line with an
open arrowhead back to the originating lifeline, and above this dotted line you place the
return value from the operation.
The secSystem object returns userClearance to the system object when the
getSecurityClearance method is called. The system object returns availableReports
when the getAvailableReports method is called.
The use of return messages depends on the level of detail/abstraction that is being
modeled.
Self Messaging:
When modeling a sequence diagram, there will be times that an object will need
to send a message to itself.
A purist would argue that an object should never send a message to itself.
To draw an object calling itself, you draw a message as you would normally, but
instead of connecting it to another object, you connect the message back to the
object itself.
Self Messaging:
Messages: Guards
Messages: Guards
Alternatives allow the modeling of the classic "if then else" logic (e.g., if I buy
three items, then I get 20% off my purchase; else I get 10% off my purchase).
Operands are separated by a dashed line. Each operand is given a guard to test
against, and this guard is placed towards the top left section of the operand on top
of a lifeline.
If an operand's guard equates to "true," then that operand is the operand to follow.
2011: J Paul Gibson T&MSP: Software Engineering CSC7322/UML.75
Sequence Diagrams: the basic elements
Alternatives: example
The option combination fragment is used to model a sequence that, given a certain
condition, will occur; otherwise, the sequence does not occur.
An option is used to model a simple "if then" statement (i.e., if there are fewer than
five donuts on the shelf, then make two dozen more donuts).
The text "opt" is placed inside the frame's namebox, and in the frame's content area
the option's guard is placed towards the top left corner on top of a lifeline. Then the
option's sequence of messages is placed in the remainder of the frame's content
area.
In UML 2, modeling a repeating sequence has been improved with the addition of
the loop combination fragment.
You draw a frame, and in the frame's namebox the text "loop" is placed. Inside the
frame's content area the loop's guard is placed towards the top left corner, on top of
a lifeline.
Then the loop's sequence of messages is placed in the remainder of the frame's
content area.
In a loop, a guard can have two special conditions tested against in addition to the
standard Boolean test.
With these you can combine (reuse) the simpler sequences to produce more
complex sequences.
This means that you can abstract out a complete, and possibly complex, sequence
as a single conceptual unit.
The parallel combination fragment is drawn using a frame, and you place the text
"par" in the frame's namebox.
You then break up the frame's content section into horizontal operands separated
by a dashed line. Each operand in the frame represents a thread of execution done
in parallel.
This is more or less the same information shown by Sequence Diagrams but there
the emphasis is put on how the interactions occur in time while the Collaboration
Diagrams put the relationships between the objects and their topology in the
foreground.
Example Structure:
More diagrams:
Components, Deployment,
For actual development you will find that use cases provide
significantly more value because they describe "the
foundations" of the actual requirements and can drive
development of other models
It is important to notice that Use Case Diagrams are not suited to represent
the design, and cannot describe the internals of a system.
Use Case Diagrams are meant to facilitate the communication with the
future users of the system, and with the customer, and are specially helpful
to determine the required features the system is to have.
Use Case Diagrams tell, what the system should do but do not — and cannot
— specify how this is to be achieved.
Associations between actors and use cases are indicated in use case
diagrams by solid lines. An association exists whenever an actor is involved
with an interaction described by a use case. Associations are modeled as
lines connecting use cases and actors to one another, with an optional
arrowhead on one end of the line. The arrowhead is often used to
indicating the direction of the initial invocation of the relationship or to
indicate the primary actor within the use case.
Hint: The arrowheads are typically confused with data flow and so their use
is sometimes best avoided.
Staff
System boundary boxes (optional). You can draw a rectangle around the use
cases, called the system boundary box, to indicates the scope of your system.
Anything within the box represents functionality that is in scope and
anything outside the box is not. System boundary boxes are rarely used,
Hint: such boxes can be usefully applied to identify which use cases will be
delivered in each major release of a system.
Hint: use packages only when diagrams become unwieldy, which generally
implies they cannot be printed on a single page, to organize a large diagram
into smaller ones.
•Include
•Extend
•Generalization
Include
The first use case often depends on the outcome of the included use case.
This is useful for extracting common behaviours from multiple use cases
into a single description.
The notation is a dashed arrow from the including to the included use case,
with the label "«include»".
This usage resembles a macro expansion where the included use case
behaviour is placed inline in the base use case behaviour. There are no
parameters or return values.
2011: J Paul Gibson T&MSP: Software Engineering CSC7322/UML.100
Use Case Diagrams
Extend
Example: Suppose you wanted to diagram the interactions between a user, a web
browser, and the server it contacts. Since you can only have one system on the
diagram, you must choose one of the obvious "systems", such as the server. You
might then be tempted to draw interaction lines between the actors, but this is a
problem because it isn't clear what the interaction means, so it isn't helpful to
show it here. A more useful solution would be to draw two diagrams, showing all
of the interactions.
becomes
becomes
UCDs represent
functionality in a top-
down way, whereas
flow charts represent
behavior in a linear,
time-based way.
When you want to show the sequence of events on a broader scale use activity
and state diagrams.
State diagrams show the change of an object over time and are useful when an
object exhibits interesting or unusual behaviour - such as that of a user
interface component.
As always, use these diagrams only when they serve a purpose. Don't feel that
you have to draw a state diagram for every object in your system and an
activity diagram for every process. Use them where they add to your
design. You may not even include these diagrams in your design, and your
work may still be complete and useful.
start
decision point
end
guard
guard
An activity diagram shows sequences of activity states (actions to you and me)
where when one action is complete the flow immediately moves on to the next
action.
This automatic transitioning from one activity state to the next is what
distinguishes activity diagrams from their close cousin, state transition
diagrams. In state transition diagrams, transitions from one state to another
occur as the result of events, and don’t happen automatically.
State machine diagrams depict the various states that an object may be in and the
transitions between those states.
UML 2 state machine diagrams were formerly called state chart diagrams in
UML 1.x
In fact, in other modeling languages, it is common for this type of a diagram to be
called a state-transition diagram or even simply a state diagram.
A state represents a stage in the behavior pattern of an object, and like UML
activity diagrams it is possible to have initial states and final states.
An initial state, also called a creation state, is the one that an object is in when it
is first created, whereas a final state is one in which no transitions lead out of.
A transition is a progression from one state to another and will be triggered by an
event that is either internal or external to the object.
Do action
State Actions
Typically, an effect is associated with a transition. If a target state has many
transitions arriving at it, and each transition had the same effect associated
with it, it would be better to associate the effect with the target state rather
than the transitions. This can be done by defining an entry action for the
state. The diagram below shows a state with an entry action and an exit
action.
State diagrams can also show a super-state for the object. A super-state is used
when many transitions lead to the a certain state. Instead of showing all of the
transitions from each state to the redundant state a super-state can be used to 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.
Sometimes you won’t want to enter a sub-machine at the normal initial state.
For example, in the following sub-machine it would be normal to begin in the
"Initializing" state, but if for some reason it wasn’t necessary to perform the
initialization, it would be possible to begin in the "Ready" state by transitioning
to the named entry point.
A history state is used to remember the previous state of a state machine when it
was interrupted. The following diagram illustrates the use of history states. The
example is a state machine belonging to a washing machine.
In this state machine, when a washing machine is running, it will progress from
"Washing" through "Rinsing" to "Spinning". If there is a power cut, the washing
machine will stop running and will go to the "Power Off" state. Then when the power is
restored, the Running state is entered at the "History State" symbol meaning that it
should resume where it last left-off.
A state may be divided into regions containing sub-states that exist and execute
concurrently. The example below shows that within the state "Applying Brakes", the
front and rear brakes will be operating simultaneously and independently. Notice the
use of fork and join pseudo-states, rather than choice and merge pseudo-states.
These symbols are used to synchronize the concurrent threads.
Package diagrams are used to divide the model into logical containers, or
'packages', and describe the interactions between them at a high level.
Package diagrams are used to reflect the organization of packages and their
elements.
When used to represent class elements, package diagrams provide a
visualization of the namespaces.
The most common use for package diagrams is to organize use case
diagrams and class diagrams, although the use of package diagrams is not
limited to these UML elements.
Package Merge
A «merge» connector between two packages defines an implicit generalization between
elements in the source package, and elements with the same name in the target package. The
source element definitions are expanded to include the element definitions contained in the
target. The target element definitions are unaffected, as are the definitions of source package
elements that don’t match names with any element in the target package.
Package Import
The «import» connector indicates that the elements within the target package, which in this
example is a single class, use unqualified names when being referred to from the source
package. The source package's namespace gains access to the target classes; the target's
namespace is not affected.
Nesting Connectors
The nesting connector between the target package and source packages shows that the
source package is fully contained in the target package.