Introduction to UML

by K. Yue

1. Introduction to UML

Class Diagram of UML 2.2 diagram (from wikipedia):

UML 2.2 Diagram

2. Class Diagrams (Emphasis on DB applications)

Introduction:

A Simple Conceptual Modeling Process

  1. Examine application requirements to gain a good understanding of the problem.
  2. Conduct an analysis to extract concepts that may have data requirements.
  3. For each concept, design how do model the concept. Options are:
    1. by attributes
    2. by a class
    3. by associations between classes
    4. no need to model

These steps are repeated until the model reaches the necessary fidelity, accuracy and precision.

Example:

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

Specification description: 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 and Design

  1. Manufacturer: a class (template) that can be used to initiate many manufacturer objects (instances).
  2. Honda: an object of the class Manufacturer.
  3. Resolve ambiguous terms: manufacturer, may refer to the manufacturer class or a particular manufacturer (e.g. Honda).
  4. Define 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. Make additional assumptions: 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. Prepare questions: 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 clearly modeled. The operation compartments can be missed.
  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.

Note that software application modeling and database modeling has different focus.

  1. Application modeling: focus on operations (methods).
  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 much less important than data members in database modeling.
  6. Multiplicity should eventually be added, as shown in the diagram below.

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.

Associations

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

class_diagram_3.png

Note:

  1. Job is an association class.
  2. The arrow in the association "works-for" shows the direction of the association.
  3. The association "manages" is between two job objects.
  4. The {or} designation specifies the partition of the account class into two classes: person (account) and corporate (account).

Example:For:

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:

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 We will work on a problem from a previous semester.