Introduction to UML

by K. Yue

1. Resources

UML:

2. Introduction to UML

Class Diagram of UML 2.2 diagram (from wikipedia):

UML 2.2 Diagram

3. Use Case Diagrams

4. Class Diagrams (Emphasis on DB applications)

Introduction:

Example:

Problem. An used car dealership application's subsystem: information about cars and their manufacturer.

Specification: A car manufacturer has an unique id and name. A car maker may make many cars. For example, Honda, which may have an manufacturer id of 10001, makes Civic and Accord...

Analysis:

  1. Manufacturer: class (a template that can be used to initiate many manufacturer (instance).
  2. Honda: object of the class Manufacturer.
  3. Ambiguous term: manufacturer, may refer to the manufacturer class or a particular manufacturer.
  4. Synonym: manufacturer, car manufacturer, car maker. Different terms can refer to the same concept.
  5. Unique id: attribute (name), a property of the manufacturer class.
  6. Additional assumption: Every manufacturer object must have an unique id.
  7. 10001: attribute (value) of a manufacturer object.
  8. Name: a property of manufacturer.
  9. Additional assumption: Every manufacturer object must have a name.
  10. Car: a class as there may be many brands of cars.
  11. Question: Do we need to introduce the concept Model (e.g. Coupe, Sedan, Si Coupe)?
  12. Civic and Accord: object instance of Car.
  13. Additional assumption: Every car must have a name as its attribute.
  14. Make, or manufacture: a relationship between a manufacturer (object) and a car (object).

Class Diagram:

car1

Object Diagram:

car_2

Classes:

  1. Drawn as a rectangular box.
  2. The class names, attributes, and operations may be specified, with selected details in the name, attribute and operation compartments respectively.
  3. Attribute and operation compartments are optional.
  4. For DB modeling, the attribute compartment will eventually need to be filled.
  5. The levels of details depend on the phase of modeling.  It is a common mistake to specify too much detail in the early modeling phases.
  6. As modeling proceeds, more details are added, updated, and refined.

Example: Three phase of modeling a class in software modeling. Note that software application modeling and database modeling has different focus.

  1. Application modeling: focus on operations.
  2. Database modeling: focus on attributes (data).

Example: The following diagram show the Window class in three phases of modeling. Note that this is for software modeling, not data modeling.

class_diagram_1.png

astah_1

Example: for software modeling:

class_diagram_2.png

Example: for database modeling.

astah_2

The class Patron may be identified in the first draft of the UML class diagram.

  1. In a subsequent iteration, attributes may be added using settings of the UML tool showing visibility of the attribute members.
  2. Data types may be included using predefined data types provided by the tool.
  3. In a further iteration, stereotype may be added, such as to identify the primary key <<PK>> and simple candidate key <<unique>>.
  4. More specific user-defined types (or implementation types) may be used.
  5. Operation members may be added. They are in general less important than data members in database modeling.
  6. Multiplicity should eventually be added.

astah_3

Examples:

Class diagrams from agile modeling and wikipedia.

Example:

asta1

We may have four objects of the student class: S1, S2, S3 and S4. Each student object represents an individual student in a database application.

We may have three objects of the course class: C1, C2, and C3. Each course object represents an individual Course in the database application.

Classwork (If time allows)

Construct a reasonable class diagram for the toy library application.

Associations

Example: Note that no attributes are shown in this initial phase.

class_diagram_3.png

asta1

The association Enroll describes the association 'type'. The association is actually between two objects (a student object and a course object). Examples:

S1 -- C1: meaning student S1 is enrolled in course C1.
S1 -- C3
S2 -- C1
S2 -- C2
S2 -- C4
S3 -- C3
S4 -- C1
S4 -- C4

asta 5

Example

What do you think about these class diagrams?

(a)

asta 3

(b)

asta 4

(c)

asta 2

 

Example: Aggregation and Composition

class_diagram_4.png

What do you think about this composition and aggregation examples in: http://en.wikipedia.org/wiki/File:Congregationalism?

A not so good example from a tutorial:

class_diagram_5.png

Tips:

Classwork:

Exercise 7.16, Elmarsi, only in UML class diagram, and not ER. (Elmarsi_7_16.docx)

Example:

Student_Staff_Faculty.asta

asta 6

What are the associations between student, staff and faculty?

Example:

class_diagram_6.png

class_diagram_7.png

Constructing class diagrams: some tips

  1. There are many methodologies and best practice tips to construct effective class diagrams.
  2. There are many possible modeling options: e.g. classes versus attributes, classes versus associations, multiplicity, etc.
  3. Need to fully understand the assumptions and implications when making modeling decisions.
  4. Do not model implementation details in earlier modeling phases.

Classwork (If time allows)

The goal is to build a toy prototype database to partially support a portion of a drastically simplified student group system (SGS). Construct an UML class diagram to capture and model the partial requirements below. You should list class names, attributes with multiplicities, and associations with multiplicities. Roles of associations should also be provided when appropriate. Multiplicities should be as specific as possible. Show the stereotype <<PK>> (primary key) when applicable.

In SGS, students can form groups to do things and join these groups as members. The student id (a unique identifier that can serve as a key), name, email, and phone of a student should be recorded. All are mandatory fields with the exception of phone, which is optional. When a student joins a group as a member, the join time must be stored, together with an optional comment.

A group must have a unique id and a name. It may also have a description. It can be a top group or a lower level group. A group may have some subgroups, which are themselves groups, and thus may have their own subgroups. A top level group must have a faculty supervisor, so a faculty id must be stored. A member can make comments on a top level group (but not a lower level group). Such comments should be recorded with the time they were made.

Use Astah if you have a computer.