UML Reference Card
UML Reference Card
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.