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)

2.1 Introduction:

2.2 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 should it be modeled? Major options are:
    1. by attributes
    2. by a class
    3. by associations between classes (including special associations, such as composition, aggregation, generalization, etc.)
    4. no need to model (as it does not represent data requirement)

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

Example:

Problem. A 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

Some observations:

  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: e.g., the term "manufacturer" may refer to the manufacturer class, or a particular manufacturer (a manufacturer object such as Honda).
  4. Define synonym: manufacturer, car manufacturer, car maker. Different terms can refer to the same concept.
  5. "Unique id": may be modeled as an 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 the id of a manufacturer object.
  8. Name: a property of a 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 instances 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

2.3 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 may not be needed.
  5. The levels of details depend on the phases 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. Software modeling: focus on operations (methods, especially public methods).
  2. Database modeling: focus on attributes (data).

Example: The following sequence of diagrams of how the modeling of the used car dealership application may proceed.

Initial version: v0.0.1.0:

Version v0.0.1.1:

Version v0.0.1.2:

  1. Decided to split the concept 'car' into two concepts 'car model' and 'car'. Adjust associations.
  2. Add some type information.

Version v0.0.1.3:

  1. Add an association between Payment and Car.
  2. Add multiplicity of the association "of the model of":
    1. A car must be made of one car model.
    2. There may be many cars made of the same model.
  3. Add multiplicity of 1 to the attributes Amount and PayTime of the class Payment. They are mandatory.

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 data modeling.
  6. Multiplicity should eventually be added, as shown in the diagram below.

astah_3

Check out the introductions to class diagrams from agile modeling and wikipedia.

More Properties of Classes

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.

2.4 Associations

Example: Note that no attribute is 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'. An 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: (The associations S1--C2 and S1-C4 do not exist. This means the student S1 has not enrolled in the C2 or C4.)
S2 -- C1
S2 -- C2
S2 -- C4
S3 -- C3
S4 -- C1
S4 -- C4

2.5 Multiplicity

asta 5

Example

What do you think about these class diagrams?

(a)

asta 3

Assumptions made:

  1. A student may take many courses.
  2. Not sure whether a student is allowed to take zero course since * (instead of 0..* or 1..* is used).
  3. A course may have many students enrolled.
  4. Not sure whether a course has no student enrolled since * (instead of 0..* or 1..* is used).

(b)

asta 4

Assumptions made:

  1. A student must be enrolled in one or more courses (may not be a reasonable assumption).
  2. A course may have 0 or more students enrolled.

(c)

asta 2

Assumptions made:

  1. A student can only be enrolled in 0 or 1 course only (sound not reasonable).
  2. A course may have many students enrolled.
  3. Not sure whether a course has no student enrolled since * (instead of 0..* or 1..* is used).

Aggregation indicator

  1. aggregation (hollow diamond) and composition indicator (solid diamond):
  2. Aggregation models the ‘a-part-of’ relationship (whole-part). E.g., car-wheel.
  3. Composition is a strong form of aggregation: the part's lifecycle is dependent on the whole's lifecycle; e.g. university-department, building-room.
  4. They can also be represented by using multiplicity.

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?

Ternary Associations

An example from a tutorial:

class_diagram_5.png

Notes:

Generalization and Specialization

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.

3. Example: toyu

A reasonable conceptual model of the toyu database in UML: