Why use the UML?
(1) Many people think in pictures.
(2) You'll be able to share your ideas with others.
(3) A picture can express a lot of words.
(4) UML is becoming valuable in the job market.
(5) You will think of more ideas and be able to spot bad ones.
How do I use the UML?
There are four ways people use the UML:
| Purpose | Tool |
|---|---|
| A rough sketch of an idea. | Chalk board. Pencil and paper. Hint. Leave boxes open to the right and bottom. |
| A blueprint of some software | A drawing program like Dia or Visio. Some word processors can also do graphics. |
| Generating a program | A CASE tool like Pegasus or Rational Rose |
| Required documentation | Either use a CASE tool to reverse engineer the diagram from code, or a drawing tool. |
As a rule: keep it simple. Only do a diagram if you can see some to doing it. Omit things on a diagram that are neither important nor interesting.
How do I draw a single class in the UML?
The UML can express most things you can code in C++.
A single
box represents a class of objects. The name of the class is at the top.
In the next part of the box lists the data each object contains. In the third
part of the class box list the operations (functions) that an object can
carry out.
Notice that instead of the C++ 'string name;' we write 'name : string'. More, omit the word void!
Notice that private items (like the vertexes above) are marked with a minus sign. Public items are marked with a plus sign.
The constructors are underlined to show that they are not applied to objects. Some people omit the underline. You can also write <<constructor>> if you want to be very correct.
In fact, you don't have to show all the details unless you need to. You can omit the underlining of constructors. You can even omit constructors unless they are special in some way. Any compartments can be left out. For example the following are also pictures of the Triangle class with details suppressed.
Note: you can sketch a class in the UML quicker than you can write a C++ class.
How do I show relations between my classes using UML?
Many classes can be put on one diagram and connected together.
The following diagram says that we had to use the class Point
to define a triangle:
We can be more precise and say that a Triangle must have three Points called vertexes:
How do I draw an object in the UML?
It helps to be able to draw objects as well as classes.
The rules are simple: use a box, underline the name of the object
and its class, and put attributes in a compartment under the name.
Here for example is a simple Counter class plus object diagrams of of an
object the_count before and after a particular operation is applied
to it.
Suppose we've defined a class called Counter:
Then a recently constructed Counter object called the_count.
The same object after being sent a count() message
Can you show us an example of the UML that we can use in this class?
Here is a UML class diagram of the graphic classes in Horstman's
CCC
library.
How do I draw a complex algorithm in the UML?
To plan a complex algorithm use an
Activity diagram
(like a traditional flowchart).
I've seen a diagram with a funny diamond shape on it, what does it mean?
This is used to relate a whole to it's parts. It shows ownership.
It is used when you have
a "Has a" relationship like: "A dog has a tail".
This notation can be used to show that a class has a data member or field.
It is called
composition.
Can I show arrays and vectors in the UML?
Yes. You can show an array as an attribute with the size in brackets
(just like in C++). Vectors can vary in size so you put an asterisk
in the between the braces. You can also put these
multiplicities
on links beyween classes.
For an example, here is the code for a class called Period as part of our college model:
class Period {
private:
Time time[2];//start and finish Times
vector<Day> days;
};//end class PeriodHere are a couple of valid diagrams that show that each Period contains a pair of times and variable number of days.
A simple composition with a multiplicity of one indicates
a simple data member in the C++ class. A fixed multiplicity suggests an array.
A range of multiplicities or an asterisk suggests a more complex data structure
such as a vector, list, or set. If the order is important, then the constraint "{ordered}"
should be added.
Where can I learn more about the UML?
This is a very quick overview. There is a lot more to learn about the UML.
Here is a link to some local documentation on the UML:
[ uml.html ]
In your future career you may need a text book. If so try: Martin Fowler and K. Scott, "UML Distilled: A Brief Guide to the Standard Object Modeling Language," 3rd Ed., Addison-Wesley, 2005.
There is more in CS202 [ ../cs202/uml0.html ]
. . . . . . . . . ( end of section A Beginners Guide to The Unified Modeling Language (UML)) <<Contents | End>>
Abreviations