[Skip Navigation] [CSUSB] / [CNS] / [Comp Sci Dept] / [R J Botting] / [CSci201] / uml
[Syllabus] [Schedule] [Glossary] [Labs] [Projects] [Resources] [Grading] [Contact] [Search ]
Notes: [01] [02] [03] [04] [05] [06] [07] [08] [09] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20]
Labs: [01] [02] [03] [04] [05] [06] [07] [08] [09] [10]
Tue Sep 18 15:35:16 PDT 2007

Contents


    A Beginners Guide to The Unified Modeling Language (UML)

      What is the UML?

      UML stands for "Unified Modeling Language". The UML is a popular diagrammatic language and has become the standard way to draw software.

      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:
      PurposeTool
      A rough sketch of an idea.Chalk board. Pencil and paper. Hint. Leave boxes open to the right and bottom.
      A blueprint of some softwareA drawing program like Dia or Visio. Some word processors can also do graphics.
      Generating a programA CASE tool like Pegasus or Rational Rose
      Required documentationEither 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.

      Detailed UML Diagram of a Lab07 Triangle Class

      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.

      Simpler UML diagrams of a Triangle

      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:

      Triangle uses Point

      We can be more precise and say that a Triangle must have three Points called vertexes:

      Triangle has three Points called vertex

      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:

      Counter class

      Then a recently constructed Counter object called the_count.

      the_count when constructed has state=1

      The same object after being sent a count() message

      the_count after count() has state=1

      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.

      Graphic classes from Horstmann 3rd Edn CCC book

      How do I draw a complex algorithm in the UML?

      To plan a complex algorithm use an Activity diagram (like a traditional flowchart).

      Horstmann's Fig 8 in Chapter 5

      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".

      Each dog has a tail in the UML

      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 Period
      Here are a couple of valid diagrams that show that each Period contains a pair of times and variable number of days.

      Array and vector in the UML

      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

  1. Gnu::="Gnu's Not Unix", a long running open source project that supplies a very popular C++ compiler.
  2. KDE::="Kommon Desktop Environment".
  3. TBA::="To Be Announced", something I should do.
  4. TBD::="To Be Done", something you have to do.
  5. UML::="Unified Modeling Language", [ uml.html ] (beginner's introduction to the UML).

End