UML 2 Class Diagram
UML 2 Class Diagram
Class Diagrams
Class Notation
Classes are represented by rectangles which show the name of the class and
optionally the name of the operations and attributes. Compartments are used
to divide the class name, attributes and operations. Additionally constraints,
initial values and parameters may be assigned to classes.
In the diagram below the class contains the class name in the topmost
compartment, the next compartment details the attributes, with the "center"
attribute showing initial values. The final compartment shows the operations,
the setWidth, setLength and setPosition operations showing their
parameters. The notation that precedes the attribute or operation name
indicates the visibility of the element, if the + symbol is used the attribute or
operation has a public level of visibility, if a - symbol is used the attribute or
operation is private. In addition the # symbol allows an operation or attribute
to be defined as protected and the ~ symbol indicates package visibility.
Interfaces
An interface is a specification of behaviour that implementers agree to meet.
It is a contract. By realizing an interface, classes are guaranteed to support a
required behaviour, which allows the system to treat non-related elements in
the same way – i.e. through the common interface.
Interfaces may be drawn in a similar style to a class, with operations
specified, as shown below. They may also be drawn as a circle with no
explicit operations detailed. When drawn as a circle, realization links to the
circle form of notation are drawn without target arrows.
Tables
A table is a stereotyped class. It is drawn with a small table icon in the upper
right corner. Table attributes are stereotyped «column». Most tables will
have a primary key, being one or more fields that form a unique combination
used to access the table, plus a primary key operation which is stereotyped
«PK». Some tables will have one or more foreign keys, being one or more
fields that together map onto a primary key in a related table, plus a foreign
key operation which is stereotyped «FK».
Associations
An association implies two model elements have a relationship - usually
implemented as an instance variable in one class. This connector may include
named roles at each end, cardinality, direction and constraints. Association is
the general relationship type between elements. For more than two
elements, a diagonal representation toolbox element can be used as well.
When code is generated for class diagrams, associations become instance
variables in the target class.
Generalizations
A generalization is used to indicate inheritance. Drawn from the specific
classifier to a general classifier, the generalize implication is that the source
inherits the target's characteristics. The following diagram shows a parent
class generalizing a child class. Implicitly, an instantiated object of the Circle
class will have attributes x_position, y_position and radius and a method
display(). Note that the class Shape is abstract, shown by the name being
italicized.
The following diagram illustrates the difference between weak and strong
aggregations. An address book is made up of a multiplicity of contacts and
contact groups. A contact group is a virtual grouping of contacts; a contact
may be included in more than one contact group. If you delete an address
book, all the contacts and contact groups will be deleted too; if you delete a
contact group, no contacts will be deleted.
Association Classes
Dependencies
A dependency is used to model a wide range of dependent relationships
between model elements. It would normally be used early in the design
process where it is known that there is some kind of link between two
elements but it is too early to know exactly what the relationship is. Later in
the design process, dependencies will be stereotyped (stereotypes available
include «instantiate», «trace», «import» and others) or replaced with a more
specific type of connector.
Traces
The trace relationship is a specialization of a dependency, linking model
elements or sets of elements that represent the same idea across models.
Traces are often used to track requirements and model changes. As changes
can occur in both directions, the order of this dependency is usually ignored.
The relationship's properties can specify the trace mapping, but the trace is
usually bi-directional, informal and rarely computable.
Realizations
The source object implements or realizes the destination. Realize is used to
express traceability and completeness in the model - a business process or
requirement is realized by one or more use cases which are in turn realized
by some classes, which in turn are realized by a component, etc. Mapping
requirements, classes, etc. across the design of your system, up through the
levels of modelling abstraction, ensures the big picture of your system
remembers and reflects all the little pictures and details that constrain and
define it. A realization is shown as a dashed line with a solid arrowhead and
the «realize» stereotype.
Nestings
A nesting is connector that shows that the source element is nested within
the target element. The following diagram shows the definition of an inner
class although in EA it is more usual to show them by their position in the
Project View hierarchy.
Object Diagrams
A classifier element can have any number of attributes and operations. These
aren’t shown in an object instance. It is possible, however, to define an
object’s run time state, showing the set values of attributes in the particular
instance.
The following diagram shows an object diagram with its defining class
diagram inset, and it illustrates the way in which an object diagram may be
used to test the multiplicities of assignments in class diagrams. The car class
has a 1-to-many multiplicity to the wheel class, but if a 1-to-4 multiplicity
had been chosen instead, that wouldn’t have allowed for the three-wheeled
car shown in the object diagram.
UML 2 Composite Structure Diagram
Composite Diagrams
Class elements have been described in great detail in the section on class
diagrams. This section describes the way that classes can be displayed as
composite elements exposing interfaces and containing ports and parts.
Part
A part is an element that represents a set of one or more instances which are
owned by a containing classifier instance. So for example, if a diagram
instance owned a set of graphical elements, then the graphical elements
could be represented as parts, if it were useful to do so to model some kind
of relationship between them. Note that a part can be removed from its
parent before the parent is deleted, so that the part isn't deleted at the same
time.
Port
Note that the circle notation does not show the interface operations. When
interfaces are shown as being owned by classes, they are referred to as
exposed interfaces. An exposed interface can be defined as either provided
or required. A provided interface is an affirmation that the containing
classifier supplies the operations defined by the named interface element and
is defined by drawing a realisation link between the class and the interface. A
required interface is a statement that the classifier is able to communicate
with some other classifier which provides operations defined by the named
interface element and is defined by drawing a dependency link between the
class and the interface.
Collaboration
A collaboration defines a set of co-operating roles used collectively to
illustrate a specific functionality. A collaboration should only show the roles
and attributes required to accomplish its defined task or function. Isolating
the primary roles is an exercise in simplifying the structure and clarifying the
behaviour, and also provides for re-use. A collaboration often implements a
pattern.
A collaboration element is shown as an ellipse.
Role Binding
Represents
A represents connector may be drawn from a collaboration to a classifier to
show that a collaboration is used in the classifier. It is shown as a dashed line
with arrowhead and the stereotype «represents».
Occurrence
An occurrence connector may be drawn from a collaboration to a classifier to
show that a collaboration represents(sic) the classifier. It is shown as a
dashed line with arrowhead and the stereotype «occurrence».
UML 2 Package Diagram
Package Diagrams
Package Diagrams are used to reflect the organization of packages and their
elements. When used to represent class elements package diagrams are
used to provide a visualization of the namespaces. The most common uses
for Package diagrams is to use them to organize Use-Case Diagrams and
Class diagrams, although the use of Package Diagrams is not limited to these
UML elements.
Packages are represented in UML 2.0 as folders and contain the elements
that share a namespace; all elements within a package must have a unique
identifier. The Package must show the Package name and can optionally
show the elements within the Package in extra compartments.
Package Merge
Package Import
The «import» connector indicates that the elements within the target
package, which in this example is a single class, the target package, will be
imported into the source package. The Source Package’s namespace will gain
access to the Target’s class/s; the Target’s namespace is not affected.
Nesting Connectors
The nesting connector between the target package and source packages
reflect what the package contents reveal.
Component Diagrams
Required Interfaces
Deployment Diagrams
Node
A Node is either a hardware or software element. It is shown as a 3-
dimensional box shape, as below
Node Instance
Artifact
An Artifact is a product of the software development process. That may include process
models (e.g. Use Case models, Design models etc), source files, executables,
design documents, test reports, prototypes, user manuals and so on.
Association
In the context of a deployment diagram, an association represents a
communication path between nodes. The following diagram shows a
deployment diagram for a network, showing network protocols as
stereotypes and also showing multiplicities at the association ends.
Node as Container
The Use Case Model captures the requirements of a system. Use cases are a
means of communicating with users and other stakeholders about what the
system is intended to do.
Actors
A Use Case Diagram shows the interaction between the system and entities
external to the system. These external entities are referred to as Actors.
Actors represent roles which may include human users, external hardware or
other systems. An actors is usually drawn as a named stick figure, or
alternatively as a class rectangle with the «actor» keyword.
Use Cases
The uses connector can optionally have multiplicity values at each end, as in
the following diagram which shows that a customer may only have one
withdrawal session at a time, but a bank may have any number of customers
making withdrawals concurrently.
• Requirements
• Constraints
• Scenarios
• Scenario Diagrams
• Additional information.
Name and Description
Requirements
The requirements define the formal functional requirements that a use case
must supply to the end user. They correspond to the functional specifications
found in structured methodologies. A requirement is a contract or promise
that the Use Case will perform an action or provide some value to the
system.
Constraints
A constraint is a condition or restriction that a Use Case operates under and
includes pre, post and invariant conditions. A precondition specifies the
conditions that need to be met before the Use Case can proceed. A post
condition is used to document the change in conditions that must be true
after the execution of the Use Case. An invariant condition specifies the
conditions that are true throughout the execution of the Use Case
Scenarios
A Scenario is a formal description of the flow of events that occur during the
execution of a Use Case instance. It defines the specific sequence of events
between the system and the external Actors. It is normally described in text
and corresponds to the textual representation of the Sequence Diagram.
Uses Cases may contain the functionality of another Use Case as part of their
normal processing. In general it is assumed that any included use case will
be called every time the basic path is run. An example of this is to have the
execution of the Use Case <Card Identification> to be run as part of a Use
Case <Withdraw>.
Use Cases may be included by one or more Use Case, helping to reduce the
level of duplication of functionality by factoring out common behavior into
Use Cases that are re-used many times.
Extending Use Cases
One Use Case may be used to extend the behavior of another; this is
typically used in exceptional circumstances. For example, if before modifying
a particular type of customer order, a user must get approval from some
higher authority, then the <Get Approval> Use Case may optionally extend
the regular <Modify Order> Use Case.
Extension Points
The point at which an extending use case is added can be defined by means
of an extension point.
System Boundary
It is usual to display use cases as being inside the system and actors as being outside the
system.
UML 2 Communication Diagram
Communication Diagrams
Sequence Diagrams
Lifelines
A lifeline represents an individual participant in a sequence diagram. A lifeline
will usually have a rectangle containing its object name. If its name is self
then that indicates that the lifeline represents the classifier which owns the
sequence diagram..
Messages
Messages are displayed as arrows. Messages can be complete, lost or found;
synchronous or asynchronous; call or signal. In the following diagram, the
first message is a synchronous message (denoted by the solid arrowhead)
complete with an implicit return message; the second message is
asynchronous (denoted by line arrowhead) and the third is the asynchronous
return message (denoted by the dashed line).
Execution Occurrence
A thin rectangle running down the lifeline denotes the execution occurrence
or activation of a focus of control. In the previous diagram, there are three
execution occurrences. The first is the source object sending two messages
and receiving two replies; the second is the target object receiving a
synchronous message and returning a reply; and the third is the target
object receiving an asynchronous message and returning a reply.
Self Message
Lost messages are those that are either sent but do not arrive at the
intended recipient, or which go to a recipient not shown on the current
diagram. Found messages are those that arrive from an unknown sender, or
from a sender not shown on the current diagram. They are denoted going to
or coming from an endpoint element.
Combined Fragments
It was stated earlier that Sequence diagrams are not intended for showing
complex procedural logic. While this is the case, there are a number of
mechanisms that do allow for adding a degree of procedural logic to
diagrams and which come under the heading of combined fragments. A
combined fragment is one or more processing sequence enclosed in a frame
and executed under specific named circumstances. The fragments available
are:
Gate
A gate is a connection point for connecting a message inside a fragment with
a message outside a fragment. EA shows a gate as a small square on a
fragment frame.
Part Decomposition
An object can have more than one lifeline coming from it. This allows for
inter- and intra-object messages to be displayed on the same diagram.
Interaction Occurrence
All the same controls from activity diagrams (fork, join, merge etc) can be
used on Interaction Overview diagrams to put the control logic around the
lower level diagrams. The following example depicts a sample sale process
with sub-processes abstracted within interaction occurrences.
UML 2 Activity Diagram
Activity Diagrams
Activities
An activity is the specification of a parameterized sequence of behaviour. An
activity is shown as a round-cornered rectangle enclosing all the actions,
control flows and other elements that make up the activity.
Actions
An action represents a single step within an activity. Actions are denoted by
round-cornered rectangles.
Action Constraints
Control Flow
A control flow shows the flow of control from one action to the next. Its
notation is a line with an arrowhead.
Initial Node
There are two types of final node: activity and flow final nodes. The activity
final node is depicted as a circle with a dot inside.
The difference between the two node types is that the flow final node
denotes the end of a single control flow; the activity final node denotes the
end of all control flows within the activity.
An object flow is a path along which objects or data can pass. An object is
shown as a rectangle.
An object flow must have an object on at least one of its ends. A shorthand
notation for the above diagram would be to use input and output pins.
A data store is shown as an object with the «datastore» keyword.
Decision nodes and merge nodes have the same notation: a diamond shape.
They can both be named. The control flows coming away from a decision
node will have guard conditions which will allow control to flow if the guard
condition is met. The following diagram shows use of a decision node and a
merge node.
Forks and joins have the same notation: either a horizontal or vertical bar
(the orientation is dependent on whether the control flow is running left to
right or top to bottom). They indicate the start and end of concurrent threads
of control. The following diagram shows an example of their use.
A join is different from a merge in that the join synchronises two inflows and
produces a single outflow. The outflow from a join cannot execute until all
inflows have been received. A merge passes any control flows straight
through it. If two or more inflows are received by a merge symbol, the action
pointed to by its outflow is executed two or more times.
Expansion Region
Exception Handlers
Partition
An activity partition is shown as either horizontal or vertical swimlanes. In
the following diagram, the partitions are used to separate actions within an
activity into those performed by the accounting department and those
performed by the customer.
UML 2 State Machine Diagram
As an example, the following State Machine Diagram shows the states that a
door goes through during its lifetime.
The door can be in one of three states: Opened, Closed or Locked. It can
respond to the events Open, Close, Lock and Unlock. Notice that not all
events are valid in all states: for example, if a door is Opened, you cannot
lock it until you close it. Also notice that a state transition can have a guard
condition attached: if the door is Opened, it can only respond to the Close
event if the condition doorWay->isEmpty is fulfilled. The syntax and
conventions used in State Machine Diagrams will be discussed in full in the
following sections.
States
The Initial State is denoted by a filled black circle and may be labelled with a
name. The Final State is denoted by a circle with a dot inside and may also
be labelled with a name.
Transitions
Transitions from one state to the next are denoted by lines with arrowheads.
A transition may have a trigger, a guard and an effect, as below.
State Actions
In the transition example above, an Effect was associated with the transition.
If the target state had 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.
It is also possible to define actions that occur on events, or actions that
always occur. It is possible to define any number of actions of each type.
Self-Transitions
A state can have a transition that returns to itself, as in the following
diagram. This is most useful when an effect is associated with the transition.
Compound States
Entry Point
The following diagram shows the state machine one level up:
Exit Point
Choice Pseudo-State
History States
Concurrent Regions
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.
Timing Diagrams
UML timing diagrams are used to display the change in state or value of one
or more elements over time. It can also show the interaction between timed
events and the time and duration constraints that govern them.
State Lifeline
A state lifeline shows the change of state of an item over time. The X-axis
displays elapsed time in whatever units are chosen while the Y-axis is
labelled with a given list of states. A state lifeline is shown below.
Value Lifeline
A value lifeline shows the change of value of an item over time. The X-axis
displays elapsed time in whatever units are chosen, the same as for the state
lifeline. The value is shown between the pair of horizontal lines which crosses
over at each change in value. A value lifeline is shown below.
State and Value Lifelines can be stacked one on top of another in any
combination. They must have the same X-axis. Messages can be passed from
one lifeline to another. Each state or value transition can have a defined
event, a time constraint which indicates when an event must occur, and a
duration constraint which indicates how long a state or value must be in
effect for. Once these have all been applied, a timing diagram may look like
the following.