Sunteți pe pagina 1din 6

#112 Get More Refcardz! Visit refcardz.

com

CONTENTS INCLUDE:

UML
n
About UML

Getting Started with


n
Structural Diagrams
n
Behavioral Diagrams
n
Interaction Diagrams
n
Hot Tips and more...

By James Sugrue

ABOUT UML Interfaces


Hot Interface names and operations are
Tip usually represented in italics.
The Unified Modeling Language is a set of rules and notations
for the specification of a software system, managed and  
created by the Object Management Group. The notation Relationship Description
provides a set of graphical elements to model the parts of
Dependency A weak, usually transient, relationship that illustrates that a
the system. class uses another class at some point.
“...uses a…”
This Refcard outlines the key elements of UML to provide you
with a useful desktop reference when designing software.

UML Tools
There are a number of UML tools available, both Figure 2: ClassA has dependency on ClassB
Hot commercial and open source, to help you document
Tip your designs. Standalone tools, plug-ins and UML
Association Stronger than dependency, the solid line relationship
indicates that the class retains a reference to another class
“…has a...” over time.
editors are available for most IDEs.
Diagram Types
UML 2 is composed of 13 different types of diagrams as
www.dzone.com

defined by the specification in the following taxonomy.


Figure 3: ClassA associated with ClassB
STRUCTURAL DIAGRAMS Aggregation More specific than association, this indicates that a class is a
container or collection of other classes. The contained classes
“…owns a…” do not have a life cycle dependency on the container, so
Class Diagrams
when the container is destroyed, the contents are not. This is
Class diagrams describe the static structure of the classes depicted using a hollow diamond.
in your system and illustrate attributes, operations and
relationships between the classes.

Modeling Classes
The representation of a class has three compartments.

Figure 4: Company contains Employees


Getting Started with UML

Figure 1: Class representation


  Get over 90 DZone Refcardz
From top to bottom this includes:
FREE from Refcardz.com!
• Name which contains the class name as well as the
stereotype, which provides information about this
class. Examples of stereotypes include <<interface>>,
<<abstract>> or <<controller>>.

• Attributes lists the class attributes in the format


name:type, with the possibility to provide initial values
using the format name:type=value
•O
 perations lists the methods for the class in the format
method( parameters):return type.

Operations and attributes can have their visibility annotated as


follows: + public, # protected, - private, ~ package

DZone, Inc. | www.dzone.com


2
Getting Started with UML

Composition More specific than aggregation, this indicates a strong life


cycle dependency between classes, so when the container is
“…is part of...” destroyed, so are the contents. This is depicted using a filled
diamond.

Figure 9: A simple object diagram


 

The object element may also have extra information to model


the state of the attributes at a particular time, as in the case of
Figure 5: StatusBar is part of a Window
myAccount in the above example.
Generalization Also known as inheritance, this indicates that the subtype is a
“…is a…” more specific type of the super type. This is depicted using a Component Diagrams
hollow triangle at the general side of the relationship. Component diagrams are used to illustrate how components
of a system are wired together at a higher level of abstraction
than class diagrams. A component could be modeled by one
or more classes.

A component is modeled in a rectangle with the


Figure 6: Ford is a more specific type of Car <<component>> classifier and an optional component icon:

Association Classes
Sometimes more complex relationships exist between classes,
where a third class contains the association information.
 
Figure 10: UML representation of a single component

Assembly Connectors
The assembly connector can be used when one component
needs to use the services provided by another.

 
Figure 7: Account associates the Bank with a Person  
Figure 11: AccountManagement depends on the CreditChecker services
Annotating relationships
For all the above relationships, direction and multiplicity can Using the ball and socket notation, required or provided
be expressed, as well as an annotation for the relationship. interfaces are illustrated as follows
Direction is expressed using arrows, which may be bi-directional.

The following example shows a multiple association, between


ClassA and ClassB, with an alias given to the link.
 
Figure 12: Required and provided interface notation

Port Connectors
  Ports allow you to model the functionality that is exposed to
Figure 8: Annotating class relationships the outside world, grouping together required and provided
Relationships can also be annotated with constraints to interfaces for a particular piece of functionality. This is
illustrate rules, using {} (e.g. {ordered}). particularly useful when showing nested components.

Notes
Notes or comments are used across all
Hot UML diagrams. They used to hold useful
Tip information for the diagram, such as
explanations or code samples, and can  
be linked to entities in the diagram.

Object Diagrams
Object diagrams provide information about the relationships  
Figure 13: Nested component diagram showing use of ports
between instances of classes at a particular point in time. As
you would expect, this diagram uses some elements from class Composite Structure Diagrams
diagrams. Composite structure diagrams show the internal structure of a
class and the collaborations that are made possible.
Typically, an object instance is modeled using a simple
rectangle without compartments, and with underlined text of The main entities in a composite structure diagram are parts,
the format InstanceName:Class ports, connectors, collaborations, as well as classifiers.

DZone, Inc. | www.dzone.com


3
Getting Started with UML

Parts
Represent one or more instances owned by the containing
instance. This is illustrated using simple rectangles within the
owning class or component. Relationships between parts may
also be modeled.
 
Figure 17: Deployment diagram example

Package Diagrams
Package diagrams show the organization of packages and the
 
Figure 14: Diagram class with a Square and Line as part of its structure elements inside provide a visualization of the namespaces that
will be applied to classes. Package diagrams are commonly
Ports
used to organize, and provide a high level overview of, class
Represent externally visible parts of the structure. They are
diagrams.
shown as named rectangles at the boundary of the owning
structure. As in component diagrams, a port can specify the As well as standard dependencies, there are two specific
required and provided services. types of relationships used for package diagrams. Both are
depicted using the standard dashed line dependency with the
Connectors
appropriate stereotype (import or merge).
Connectors bind entities together, allowing them to interact
at runtime. A solid line is typically drawn between parts. The •P
 ackage Import
name and type information is added to the connector using a Used to indicate that the importing namespace adds
name:classname format. Multiplicity may also be annotated on the names of the members of the package to its
the connector. own namespace. This indicates that the package can
access elements within another package. Unlabeled
dependencies are considered imports.
 
Figure 15: A connector between two parts • Package Merge
Used to indicate that the contents of both packages
Collaborations
are combined in a similar way to the generalization
Represents a set of roles that can be used together to achieve
relationship.
some particular functionality. Collaborations are modeled using
a dashed ellipse.

 
Figure 18: Package merge example

Figure 16: Collaboration between a number of entities


  BEHAVIORAL DIAGRAMS

Modeling Patterns Using Collaborations Use Case Diagrams


Sometimes a collaboration will be an Use case diagrams are a useful, high level communication tool
to represent the requirements of the system. The diagram
Hot implementation of a pattern. In such
shows the interaction of users and other external entities with
Tip cases a collaboration is labeled with the
  the system that is being developed.
pattern and each part is linked with a
description of its role in the problem. Graphical Elements
Entity Description
Deployment Diagrams
Actor Actors represent external entities in the system and can be
Deployment diagrams model the runtime architecture of the
human, hardware or other systems. Actors are drawn using
system in a real world setting. They show how software entities a stick figure. Generalization relationships can be used to
are deployed onto physical hardware nodes and devices. represent more specific types of actors, as in the example.
Use Case A use case represents a unit of functionality that can interact
Association links between these entities represent
with external actors or related to other use cases. Use cases
communication between nodes and can include multiplicity. are represented with a ellipse with the use case name inside.

Entity Description Boundary Use cases are contained within a system boundary, which is
Node Either a hardware or software element shown as a 3D box depicted using a simple rectangle. External entities must not
shape. Nodes can have many stereotypes, indicated by an be placed within the system boundary
appropriate icon on the top right hand corner.
Graphical Elements
An instance is made different to a node by providing an
underlined “name:node type” notation. Notation Description
Includes Illustrates that a base use case may include another, which
Artifact An artifact is any product of software development, including implies that the included use case behavior is inserted into
source code, binary files or documentation. It is depicted the behavior of the base use case.
using a document icon in the top right hand corner.

DZone, Inc. | www.dzone.com


4
Getting Started with UML

Extends Illustrates that a particular use case provides additional Graphical Elements
functionality to the base use case, in some alternative flows. Section Description
This can be read to mean that it’s not required to complete
the goal of the base use case. Action Represents one step in the program flow, illustrated using a
rounded rectangle.

Generalization Used when there is a common use case that provides basic
functionality that can be used by a more specialized use case. Constraints Action constraints are linked to an action in a note with text
of the format <<stereotype>>{constraint}
Multiplicity
Hot Like normal relationships, all use case relationships
Tip can include multiplicity annotations.
Start Node The start node is used to represent where the flow begins.
This is illustrated using a single back spot.

Activity Final Node Represents the end of all control flows within the activity.

Flow Final Node Represents the end of a single flow.

Control Flow Represents the flow of control from one action to the next
as a solid line with an arrowhead.

Object Flow If an object is passed between activities, a representation


  of the object can be added in between the activities.
Figure 19: A simple use case diagram It is also possible represent object flow by adding a square
Documenting Use Cases representing the object on either side of the control flow.

Behind each use case there should be some text describing it. Decision Node An annotated diamond shape is used to represent
The following are typical sections in a use case definition: decisions in the control flow. This can also be used to
merge flows.
Section Description A decision node will have a condition documented that
Name and Use cases are should have verb names, and have a brief needs to be met before that path can be taken.
Description description.
Fork Node Represented using a horizontal or vertical bar, a fork
Requirements This could be a link to an external formal specification, or an node illustrates the start of concurrent threads. The same
internal listing of the requirements that this use case will fulfill. notation can be used for the joining of concurrent threads.
Constraints The pre and post conditions that apply to this use case’s
execution. Partition Swimlanes can be used in activity diagrams to illustrate
Scenarios The flow of events that occur during the execution of the use activities performed by different actors.
case. Typically this starts with one positive path, with a number of
alternative flows referenced.

Region Regions are used to group certain activities together. A


Activity Diagrams stereotype is applied to the region to identify whether it is
Activity diagrams capture the flow of a program, including iterative or parallel. Regions are illustrated using a dotted
major actions and decision points. These diagrams are useful rounded rectangle.
for documenting business processes.
State Machine Diagrams
State machine diagrams are used to describe the state
transitions of a single object’s lifetime in response to events.
State machine diagrams are modeled in a similar way to activity
diagrams.

Entity Description
State States model a moment in time for the behavior of a classifier. It
is illustrated using a rounded rectangle.

Initial Post Represents the beginning of the execution of this state


machine. Illustrated using a filled circle.

Entry Point In cases when it is possible to enter the state machine at a later
stage than the initial state this can be used. Illustrated using an
empty circle.

Final State Represents the end of the state machine execution.


Represented using a circle containing a black dot.

Exit Point Represents alternative end points to the final state, of the state
machine. Illustrated using a circle with a X.
 
Figure 20: Activity diagram

DZone, Inc. | www.dzone.com


5
Getting Started with UML

Transition Represented as a line with an arrowhead. Transitions illustrate General Lifeline Represents an individual entity in the sequence diagram,
movement between states. They can be annotated with a displayed as a rectangle. It can have a name, stereotype or
Trigger[Guard]/Effect notation. States may also have self could be an instance (using instance:class)
transitions, useful for iterative behavior.
Boundary Boundary elements are usually at the edge of the system,
State A state can also be annotated with any number of trigger/effect
such as user interface, or back-end logic that deals with
pairs, which is useful when the state has a number of transitions.
external systems.

Nested States States can themselves contain internal state machine diagrams.
Control Controller elements manage the flow of information for a
scenario. Behavior and business rules are typically managed
by such objects.

State Choice A decision is illustrated using a diamond, with a number of


Entity Entities are usually elements that are responsible for holding
transitions leaving from the choice element.
data or information. They can be thought of as beans, or
model objects.

State junction Junctions are used to merge a number of transitions from


different states. A junction is illustrated using a filled circle.
Swimlanes
Hot Swimlanes can be used to break up a sequence
Terminate Indicates that the flow of the state machine has ended, Tip diagram into logical layers. A swimlane can contain
State illustrated using an X
any number of lifelines.
Messages
History State History states can be used to model state memory, where the The core of sequence diagrams are the messages that are
state resumes from where it was last time. This is drawn using a passed between the objects modeled. Messages will usually be
circle with a H inside.
of the form messagename(parameter).
Concurrent A state can have multiple substates executing concurrently, A thin rectangle along the lifeline illustrates the execution
Region which is modeled using a dashed line to separate the parallel
tracks. Forks and merges (see activity diagram) are used to split/ lifetime for the object’s messages.
merge transitions.
Messages can be sent in both directions, and may skip past
other lifelines on the way to the recipient.
Transitions: Triggers, Guards, Effects Entity Description
Triggers cause the transition, which is usually a
Hot change in condition. A guard is a condition that must
Synchronous A message with a solid arrowhead at the end. If the
Tip evaluate to true before the transition can execute.
message is a return message it appears as a dashed line
rather than solid.
Effect is an action that will be invoked on that object.
Asynchronous A message with a line arrowhead at the end. If the
message is a return message it appears as a dashed line
rather than solid.
INTERACTION DIAGRAMS
Lost A lost message is one that gets sent to an unintended
receiver, or to an object that is not modeled in the
Interaction diagrams are a subset of behavioral diagrams that diagram. The destination for this message is a black dot.
deal with the flow of control across the modeled system.
Found A found message is one that arrives from an unknown
Sequence Diagrams sender, or from an object that is not modeled in the
Sequence diagrams describe how entities interact, including diagram. The unknown part is modeled as a black dot.
what messages are used for the interactions. All messages are
Self Message A self message is usually a recursive call, or a call to
described in the order of execution. another method belonging to the same object.

Along with class and use case, sequence diagrams are the
most used diagrams for modeling software systems. Managing Object Lifecycle
Lifeline Objects Objects don’t need to all appear
A sequence diagram is made up of a number of lifelines. Each along the top of the sequence
entity gets its own column. The element is modeled at the top diagram. When a message is
of the column and the lifeline is continued with a dashed line. Hot sent to create an object, the
The following are the options for lifeline objects, with the final Tip element’s lifeline can begin at
three the being most specific. the end of that message.
 
To terminate the lifeline, simply
Entity Description
use an X at the end of the
Actor Actors represent external entities in the system. They can be
human, hardware or other systems.
dashed line.
Actors are drawn using a stick figure.
Fragments
Fragments are sections of logic that are executed given a

DZone, Inc. | www.dzone.com


6
Getting Started with UML

particular condition. These fragments can be of many different are defined in free form instead of lifelines. The focus of this
types. diagram is object relationships between boundary, control and
entity types.
Entity Description
alt Models if then else blocks Messages between the participants are numbered to provide
sequencing information.
opt Models switch statements
break For alternative sequence of events
par Concurrent blocks
seg Set of messages to be processed in any order before continuing
strict Set of messages to be processed in strict order before continuing
neg Invalid set of messages
 
Figure 22: Simple communication diagram
critical Critical section
ignore Messages of no interest Interaction Overview Diagrams
consider The opposite to ignore. An interaction overview diagram is a form of activity diagram
where each node is a link to another type of interaction
assert Will not be shown if the assertion is invalid
diagram. This provides a useful way to give high level
loop Loop fragment
overviews or indexes of the key diagrams in your system.

 
Figure 21: Sequence Diagram Fragment

Communication Diagrams
Also known as a collaboration diagram, communication  
diagrams are similar to sequence diagrams, except that they Figure 23: Interaction Overview Diagram

ABOUT THE AUTHORS RECOMMENDED BOOK


James Sugrue has been editor at both Javalobby Designers Erich Gamma, Richard Helm, Ralph Johnson,
and Eclipse Zone for over two years, and loves every and John M. Vlissides put together this excellent guide to
minute of it. By day, James is a software architect at offer simple solutions to common design problems. They
Pilz Ireland, developing killer desktop software using first describe what patterns are and how they can help
Java and Eclipse all the way. While working on desktop you design object-oriented software. Then they cover how
technologies such as Eclipse RCP and Swing, James also patterns fit into the development process and how they
likes meddling with up and coming technologies such can be leveraged to efficiently solve design problems. Each
as Eclipse e4. His current obsession is developing for pattern discussed is from a real system and is based on a
the iPhone and iPad, having convinced himself that it’s a turning point for the real-world example.
software industry. BUY NOW
books.dzone.com/books/design-patterns-elements

#82

Browse our collection of over 100 Free Cheat Sheets


Get More Refcardz! Visit refcardz.com

CONTENTS INCLUDE:


About Cloud Computing
Usage Scenarios Getting Started with

Aldon Cloud#64Computing

Underlying Concepts
Cost
by...

Upcoming Refcardz
youTechnologies ®

Data
t toTier
brough Comply.
borate.
Platform Management and more...

Chan
ge. Colla By Daniel Rubio

tion:
dz. com

also minimizes the need to make design changes to support


CON

tegra ternvasll
ABOUT CLOUD COMPUTING one time events. TEN TS
INC ■
HTML LUD E:

us Ind Anti-PPaat
Basics
Automated growthHTM
ref car

Web applications have always been deployed on servers & scalable


L vs XHT technologies

nuorn

Valid
ation one time events, cloud ML
connected to what is now deemed the ‘cloud’. Having the capability to support

Network Security
Usef
Du
ti

ul M.
computing platforms alsoulfacilitate
#84
Open the gradual growth curves

n an
Page Source

o

s
Vis it

However, the demands and technology used on such servers Structure

C
faced by web applications. Tools

Core
By Key ■
Elem

Patte
has changed substantially in recent years, especially with Structur
E: al Elem ents
INC LUD gration the entrance of service providers like Amazon, Google and Large scale growth scenarios involvingents
specialized
NTS and mor equipment
rdz !

ous Inte Change

HTML
CO NTE Microsoft. es e... away by
(e.g. load balancers and clusters) are all but abstracted
Continu at Every e chang
m

About ns to isolat
relying on a cloud computing platform’s technology.
Software i-patter
space

Hadoop
rdz .co


n
Re fca

e Work
Build
riptio
and Ant
Desc
These companies have a Privat
are in long deployed
trol repos
itory
webmana applications
ge HTM
L BAS

Patterns Control lop softw n-con to



that adapt and scale
Deve
les toto large user
a versio ing and making them
bases, In addition, several cloud computing ICSplatforms support data
ment ize merg
rn
Version e... Patte it all fi minim le HTM
Manage s and mor e Work knowledgeable in amany ine to
mainl aspects related tos multip
cloud computing. tier technologies that Lexceed the precedent set by Relational
space Comm and XHT

ref ca

Build
re

Privat lop on that utilize HTML MLReduce,


Practice Database Systems (RDBMS): is usedMap are web service APIs,

Deve code lines a system
d as thescalethe By An
sitory of work prog foundati
Ge t Mo

Buil Repo
This Refcard active
will introduce are within
to you to cloud riente computing, with an
d units
RATION etc. Some platforms ram support large grapRDBMS deployments.

The src
dy Ha
softw
e ine loping and Java s written in hical on of
INTEG attribute
task-o it all
softwar emphasis onDeve es by
Mainl these
ines providers, so youComm can better understand
also rece JavaScri user interfac web develop and the rris
Vis it

UML
codel chang desc
INUOU ding Task Level as the
e code
www.dzone.com

NT of buil trol what it is a cloudnize


line Policy sourc es as aplatform
computing can offer your ut web output ive data pt. Server-s e in clien ment. the ima alt attribute ribes whe
T CO cess ion con Code Orga it chang e witho likew mec ide lang t-side ge is describe re the ima
ABOU the pro ject’s vers applications. and subm with uniqu
e name
are from
sourc CLOUD COMPUTING ise hanism. fromAND
PLATFORMS web unavaila
was onc use HTML The eme pages and uages like ge file
it
(CI) is Nested s alte
rd z!

a pro evel Comm the build softw um ble. rnate can be


gration ed to Task-L Label ies to
build minim UNDERLYING CONCEPTS e and XHT rging use HTM PHP tags text that
blem activit the bare standard a very loos Tags found,
ous Inte committ to a pro USAGE SCENARIOS ate all
Autom configurat
ion cies to t
ization, ely-defi
ML as
thei
Ajax
tech L can is disp
Continu ry change cannot be (and freq
nden ymen layed
solution fective ned lang r visual eng nologies
Re fca

Label
Build
manu
al
d tool
depe deplo t need but as if
eve , a ) stalle the same nmen for stan overlap uen
(i.e. , inef Build t, use target enviro Amazon EC2: Industry standard it has
software and uagvirtualization ine. HTM , so <a>< tly are) nest
with terns problem ce pre-in whether dards
ated b></
ory. ns (i.e. Autom Redu ymen
has bec become e with a> is
via pat ticular d deploEAR) in each very little L

Subversion
reposit -patter s that Pay only cieswhat you consume
tagge or Amazon’s cloud
the curr you cho platform
computing isome
heavily based moron fine. b></ ed insid
lained ) and anti the par solution duce nden For each (e.g. WAR es t
ent stan ose to writ more e imp a></ e
not lega each othe
x” b> is
be exp text to “fi are al Depeapplication deployment
Web ge until t a
librarifew years agonmen
t enviro was similar that will softwaredard
industry standard and virtualization app
e HTM technology.
orta nt,
tterns to pro Minim packa nden
Mo re

CI can ticular con used can rity all depe all targe
s will L or XHT arent. Reg the HTM l, but r. Tags
etimes Anti-pa they
tend
es, but to most phone services:
y Integ alizeplans with le that
late fialloted resources, ts with an and XHT simplify all help ML, und ardless
L VS
XHTM <a><
in a par hes som
Centr
end,
Binar
pro cess. the practic enti ng incurred costgeme
nt
whether e a single
such
temp
resources on
were consumed
t enviro
nmen
orthenot. Virtualization MLaare your
othe
you prov
erst of L
b></
in muchallows physical piece of hardware to
ide be HTM
rily bad
Mana based
approac ed with the cial, but, implem anding
Creat targe es to actually r web
nden
cy rties are nt
of the a solid L has
into differe coding.resources
necessa pared to
chang
efi Depe prope itting utilized by multiple operating
function systems.simplerThis allows foundati job adm been arou
associat to be ben
er
Ge t

te builds commo
are not Fortuna
late Verifi e comm than on
n com Cloud computing asRun it’sremo
known etoday has changed this.
befor alitytohas irably, nd for
They they
etc.
Temp Build (e.g. bandwidth, n memory, CPU) be allocated exclusively to tely exp that som
lts whe
ually,
appear effects. Privat y, contin Every elem mov used
to be, HTML
ecte job e time
ed resu The various resourcesPerfo rm a
consumed by webperio applications
dicall (e.g. nt team
pag
individual operating entsinstances. ed to CSS
system Brow d. Earl
y HTM has expand . Whi
gration
opme because
adverse unintend d Builds sitory Build r to devel common e (HTML . ser ed far le it has don
ous Inte web dev manufacture L had very
Stage Repo
e bandwidth, memory, CPU) areIntegtallied
ration on a per-unit CI serve basis or XHT
produc tinu e Build rm an from
extensio .) All are more e its
e.com

ard ML shar limit


tern.
ack elopers rs add than
Con Refc Privat
from zero) by Perfo
(starting all majorated cloud ed man ed layout
feedb computing platforms. As a user of Amazon’s esse
term e, this
on
n. HTM EC2 cloud
ntiallycomputing es certplatform, you are result anybody
the pat
occur came
gration as based is
of the ” cycl such Build Send
autom as they builds proc
assigned esso
an operating L system
files shouin the plai
same wayain elem
as on allents
hosting The late a lack of stan up with clev y competi
supp
ous Inte tional use and test concepts
soon n text ort.
ration ors as ion with r
tinu
Integ entat
ld not in st web dar er wor ng stan
ven “build include
docum
Con be cr kar dar
the con s to the standar
oper
to rate devel
While efer of CI Gene
notion

DZone, Inc.
Cloud Computing

the
s on
expand

ISBN-13: 978-1-934238-75-2
140 Preston Executive Dr. ISBN-10: 1-934238-75-9
Suite 100
50795
Cary, NC 27513

DZone communities deliver over 6 million pages each month to 888.678.0399


919.678.0300
more than 3.3 million software developers, architects and decision
Refcardz Feedback Welcome
$7.95

makers. DZone offers something for everyone, including news,


refcardz@dzone.com
tutorials, cheatsheets, blogs, feature articles, source code and more. 9 781934 238752
Sponsorship Opportunities
“DZone is a developer’s dream,” says PC Magazine.
sales@dzone.com
Copyright © 2010 DZone, Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, rev. 1.001 10/08/09
photocopying, or otherwise, without prior written permission of the publisher.

S-ar putea să vă placă și