Está en la página 1de 2

UML REFERENCE CARD E.g.

: Associations (relationships between classes) Implementation Inheritance


Some_class «abstract»
{ author: George Jetson 1..* relationship 1..* SuperClass
modified: 10/6/2999 A A’s role in B B’s role in A B
- void concrete();
© 1998 Allen I. Holub. All Rights Reserved. checked_out: y + int override();
• Associated classes are connected by lines.
}
• The relationship is identified, if necessary, with a < or
Available from <http://www.holub.com>. • Guillemets identify stereotypes. E.g.: «static»,
> to indicate direction (or use solid arrowheads). SubClass
«abstract» «JavaBean». Can use graphic instead of
• The role that a class plays in the relationship is identi- + int override();
word.
fied on that class's side of the line. + int additional();
Static Model Diagrams • Access privileges (see below) can precede name.
• Stereotypes (like «friend») are appropriate. Outline arrows identify derivation relationships: extends,
• Inner (nested) classes identify outer class as prefix
• Unidirectional message flow can be indicated by an implements, is-a, has-properties-of, etc. Variations include:
of class name: (Outer.Inner or Outer::Inner).
arrow (but is implicit in situations where there is only
Packages 2. The attributes compartment (optional):
one role):
• During Analysis: identify the attributes (i.e. defin-
ing characteristics) of the object. Sender Receiver
• During Design: identify a relationship to a stock
Java.awt class. • Cardinality:
com.hulub
This: 1 Usually omitted if 1:1
Application
Person n Unknown at compile time, but bound.
Tools String name; 0..1 (1..2 1..n)
Interface Inheritance
1..* 1 or more
Oracle
Database
Interfaces is a more compact (and less informative) version of * 0 or more User
this:
• Example: f() { x.operation() }
Sybase
Person String Company relationship
give_me_a_raise(Employee e) x
• C++ namespace. name Implementer Iface Name
• Group together functionally-similar classes. operation()
• Derived classes need not be in the same package. Everything, here, is private. Always. Period. Employee
boss
operation()
1 <works for 1..n you_re_fired()
• Packages can nest. Outer packages are sometimes 3. The operations compartment (optional) contains employer peon
1

method definitions. Use implementation-language In C++, an interface is a class containing nothing but pure
called domains. (In the diagram, “Tools” is arguably 1..* flunkies
syntax, except for access privileges: virtual methods. Java supports them directly (c.f. “abstract
an outer package, not a domain).
class Company class,” which can contain method and field definitions in
• Package name is part of the class name (e.g. given the + public { addition to the abstract declarations.)
class fred in the flintstone package, the fully-qualified private Employee[] peon = new Employee[n];
# protected
class name is flintstone.fred). public void give_me_a_raise( Employee e ) { ... }
- private } My extension to UML: rounded corners identify interfaces.
• Generally needed when entire static-model won’t fit
If the full interface specification is in some other diagram, I
on one sheet. ~ package (my extension to UML) 1
class Employee use:
{
Classes (Box contains three compartments) • Abstract operations (C++ virtual, Java non-final) private Company employer; Implementer Name User
indicated by italics (or underline). private Employee boss;
private Vector flunkies = new Vector(); Strict UML uses the «interface» stereotype in the name
Class name • Boldface operation names are easier to read. public void you_re_fired() { ... }
Attributes: compartment of a standard class box:
}
If attributes and operations are both omitted, a more com- InterfaceName
«interface»
Operations: plete definition is assumed to be on another sheet. (A Java Vector is a variable-length array. In this case it
Operations
will hold Employee objects)
1
Java, unfortunately, defaults to “package” access when no modifier is present. In my Interfaces contain no attributes, so the attribute compart-
“flavor” of UML, a missing access privilege means “public”. ment is always empty.
1. The name compartment (required) contains the class
name and other documentation-related information:
Aggregation (comprises) • In official UML, put arbitrary constraints that affect • Top boxes represent objects, not classes. You may Loops (extension to UML)
more than one relationship in a “comment” box, as optionally add “:class” to the name if desired.
Whole Part shown. I usually leave out the box. • Vertical lines represent the objects “life line”, or exist- Sender Every
• Destroying the “whole” does not destroy the parts. ence. do_it() Receiver
Qualified Association • Broken lifeline indicates the object is inactive, a rect-
• Cardinality is allowed.
angle indicates the object is active. message()
User
Composition (has) relationship • represent messages being sent.
add(String key, key Item
Item value) bag • (optional if synchronous) represent method
Container Item
role return. (May label arrow with name/type of returned • Don’t think loops, think what the loop is accomplish-
• Hash tables, associative arrays, etc. ing.
object).
• The parts are destroyed along with the whole. • Typically, you need to send some set of messages to
• Sending object’s class must have:
• Doesn’t really exist in Java. class User
every element in some collection. Do this with every.
{ 1. An association of some sort with the receiving
• In C++: • You can get more elaborate (every receiver where x<y)
// A Hashtable is an associative array, indexed objects class.
// by some key and containing some value. • The diagram above comes from:
class Container private Hashtable bag = new HashTable();
2. The receiver-side class’s “role” must be the same as
{ the name of the receiving object. sender_class receiver_class
Obj item1; private void add(String key, Item value) { 1 n
Obj *item2; void do_it() void message()
bag.put(key, value); Object Creation sender receiver
public: }
Whole() { item2 = new Obj; } }
~Whole(){ delete item2; } Sender
and maps to the following code:
};
Association Class class sender_class
new {
Constraint <travels on Receiver receiver_class receiver[n];
Airline Person
carrier passenger public do_it() {
Item for(int i = 0; i < n; ++i)
{ordered}
Container receiver[i].message();
role Identity key() Ticket }
• The new instance appears at end of creation message
Date when; <buys }
Seat where; arrow.
Container Airport to; • Destruction is accomplished by terminating the lifeline
Collection {or} Airport from; Arrow Styles for Messages
with a large X:
Container
Sender
• Use when a class is required to define a relationship. Symbol Type Description
* member-of *
• Somewhere, an additional relationship is required to Simple Don’t care. Usually read as the
Comittee {subset} Person new
show ownership. (The one between person and Ticket Receiver same as synchronous.
chair-of *
1 in the current example).
message() x Synchronous Sender blocks until return.
employee employer Asynchronous Handler returns immediately and
Comittee * 0..1 Comittee Dynamic-Model (Sequence) Diagrams both sender and receiver work
simultaneously.
0..1 *
Objects and Messages (new style) Conditions
boss peon Asynchronous Callbacks
{person.employer ==
Person.boss.employer} Sender Receiver
Sender Receiver
Sender Receiver

[cond_expr] message()
message() message()
• A constrained relationship requires some rule to be
applied (e.g. {ordered}). Often combined with aggre- callback()
gation, composition, etc.
message() • Message sent only if conditional expression is true.
• In the case of {or}, only one of the indicated relation-
• The cond_expr is typically expressed in the imple-
ships will exist at any given moment (a C++ union, or
mentation language. • Callback occurs while Sender is potentially executing
reference to a base class).
something else.
• {subset} does the obvious.