name: inverse
layout: true
class: center, middle, inverse
.indexlink[[<i class="fa fa-arrow-circle-up"></i>](#) [<i class="fa fa-list-ul"></i>](#index) <a href="#" class="color"><i class="fa fa-tint"></i></a>]
---
name: top
layout: true
class: top, left
.indexlink[[<i class="fa fa-arrow-circle-up"></i>](#) [<i class="fa fa-list-ul"></i>](#index) <a href="#" class="color"><i class="fa fa-tint"></i></a>]
---
name: normal
layout: true
class: left, middle
.indexlink[[<i class="fa fa-arrow-circle-up"></i>](#) [<i class="fa fa-list-ul"></i>](#index) <a href="#" class="color"><i class="fa fa-tint"></i></a>]
---
name: uml
class: middle, center
template:inverse
# UML Conceptual Model
Gonçalo Gonçalves
[gflcg@fe.up.pt](mailto:gflcg@fe.up.pt)
.footnote.right[-- original slides by <a target=_blank href="https://silvae86.github.io">João Rocha da Silva</a>, based on the <a target=_blank href="https://dl.acm.org/citation.cfm?id=1554749">book</a> by Ullman and Widom.]
---
template: inverse
name: index
# Index
.index[
.indexpill[[Purpose](#purpose)]
.indexpill[[Classes](#classes)]
.indexpill[[Attributes](#attributes)]
.indexpill[[Associations](#associations)]
.indexpill[[Multiplicity](#multiplicity)]
.indexpill[[Association Classes](#associationclasses)]
.indexpill[[Generalizations](#generalizations)]
.indexpill[[Aggregation and Composition](#aggregationandcomposition)]
.indexpill[[Self-associations](#selfassociations)]
.indexpill[[Qualified Associations](#qualifiedassociations)]
.indexpill[[N-ary Associations](#nary_associations)]
.indexpill[[Constraints](#constraints)]
.indexpill[[Derived Elements](#derived_elements)]
]
.index[
.indexpill[[Useful Software](#software)]
.indexpill[[References](#references)]
]
---
name: purpose
## Purpose
- UML: Unified Modelling Language
- To represent the data model of an information system
- Programmers and system designers alike can understand
- Often derived from the reality of a system as described by the client (usually in text)
- Can later be converted into a relational schema
---
## A Quick Example
This is a simple UML class diagram for an online shop:
<br><br>
.center[.imgscaledup[]]
---
name: classes
## Classes
Classes are used to represent the main entities of the system.
Their syntax consists of a box with two main sections.
- The first section contains the **name** of the class
- The bottom will contain all the Class's [Attributes](#attributes), **one per line**.
.center[.imgmd[]]
.box_info[Class names are always represented in the singular, as a class denotes a **type** of entity, instead of a **set** of all entities of a certain type.]
---
name: attributes
## Attributes
- Attributes represent characteristics of all objects of the Class. They have basic types like `integer`, `double`, `string`, etc*.*
- Attributes cannot be multi-valued; if you have an attribute that can have multiple values for an object of a class, that attribute is likely a Class and should be promoted to that.
---
name: associations
## Associations
- Associations are binary relationships between classes
- Represented by a line drawn between the two classes that we want to associate
.center[.imglg[]]
At each end of the line we add the [multiplicity](#multiplicity) of the association*.*
---
name: multiplicity
## Multiplicity
- Serves to specify the cardinality (or possible number of elements) of some collections of elements.
- It is specified through an interval with a lower and upper bound, which can be infinite.
| Multiplicity | Equivalent | Cardinality |
| ------------ | ---------- | --------------------------------------------------- |
| 0..1 | | Must contain zero or one instance |
| 1..1 | 1 | Must contain exactly one instance |
| 0..* | * | Must contain zero or more instances |
| 1..* | | Must contain at least one or more instances |
| 5..5 | 5 | Must contain exactly 5 instances |
| x..y | | Must contain at least `x` and at most `y` instances |
---
name: associationclasses
template: top
## Association Classes
- Sometimes we need to represent attributes derived from an association of classes instead of classes themselves.
.center[.imgscaledup[]]
- An attribute of the product?
---
template: associationclasses
No! That would make the quantity of that product the same for every order in the system. That works if we wanted to save the **quantity in stock** of each product, for example, which only depends on the product and nothing else.
---
template: top
name: associationclassesexample1
## Association Classes (Example 1)
- A Class that results from an association between other classes.
- Used to represent attributes that depend on the associated classes.
- Can be used in many-to-many, one-to-one and one-to-many associations.
.center[.imgscaledup[]]
- Denoted by a box (usually without a title) connected by a dashed line to the solid line denoting the association between two classes.
- **Each order/product pair is associated with a single quantity.**
---
name: associationclassesexample2
template: top
## Association Classes (Example 2)
.center[.imgscaledup[]]
---
name: generalizations
## Generalizations
- Used to extract common characteristics of a set of classes. A **superclass** is created, containing the common attributes of all **subclasses**.
- It is represented by an equilateral hollow triangle pointing to the superclass and attached to it, with lines coming from it towards all subclasses.
.center[.imgfull[]]
.foonote[`Employee`s and `Customer`s are both `Person`s, so they have the attributes of a `Person`, as well as their own particular attributes]
---
## Generalizations
- Used to extract common characteristics of a set of classes. A **superclass** is created, containing the common attributes of all **subclasses**.
- It is represented by an equilateral triangle pointing to the superclass and attached to it, with lines coming from it towards all subclasses.
.center[.imgfull[]]
.foonote[`Employee`s and `Customer`s are both `Person`s, so they have the attributes of a `Person`, as well as their own particular attributes]
---
name: typesofgeneralization
## Types of Generalization
Generalizations can be
- **Overlapping** (an object can be of more than one subclass)
or
**Disjoint** (can only belong to one subclass)
- **Partial** (objects may not belong to any of the subclasses)
or
**Complete** (all objects of the superclass must be also objects of one or more subclasses)
.center[.imglg[]]
---
name: aggregationandcomposition
## Aggregation and Composition
- Compositions are special cases of Aggregations and Aggregations are special cases of Associations.
.center[.imgscaledup[]]
---
name: aggregation
.no-top-margin[
## Aggregation
]
- A special kind of association, denoted by a line between two classes.
- At one end we place a white diamond, which means `0..1`.
- For the other end, if nothing is written, the syntax implies `*`. We can restrict the lower bound of that multiplicity by writing something different, e.g. `1..*`.
.center[.imgfull[]]
.box_info[Does **not** express parent-child relationships. If the diamond end object is deleted, the related objects still live on.]
---
name: composition
.no-top-margin[
## Composition
]
- A special kind of Aggregation, where the diamond end denotes a `1..1` multiplicity
- If the object of at the diamond side is destroyed, so must be the related ones in the opposite end of the Composition
.center[.imglg[]]
- If the campus is demolished, it makes no sense to keep track of its buildings and parks anymore.
.box_info[A mnemonic: black diamond = "death". "If the whole is deleted, so are all the parts".]
---
name: selfassociations
## Self-associations
- It is also possible to specify associations between a Class and itself.
- Useful for representing hierarchies / subcomponents (one-to-many) or graphs (many-to-many).
.center[.imgscaledup[]]
---
template: top
name: qualifiedassociations
.no-top-margin[
## Qualified Associations
]
- One or more attributes of an association used to navigate from the class with the qualifier to the other
- "Access key" from the qualifier to the qualified class
.center[.imglg[]]
---
template: qualifiedassociations
- .red[Could we get the same result by using an association class?]
.center[.imglg[]]
---
## Qualified Association vs Association Class
- What's the difference?
.center[.imgscaledup[]]
<table style="border-collapse: collapse; margin-top: -20px">
<thead><th></th><th>Qualified Association</th><th>Association Class</th></thead>
<tr><td>Each person/club pair is associated with a single member number?</td><td style="text-align: center">yes</td><td style="text-align: center">yes</td></tr>
<tr><td>Each club/member number pair is associated with a single person?</td><td style="text-align: center">yes</td><td style="text-align: center">.red[no]</td></tr>
</table>
- Conclusion: qualified associations are stronger that association classes.
---
name: nary_associations
## N-ary Associations
- n-ary associations express relationships between more than 2 classes.
- Multiplicity is calculated one by one, by "fixating" all other classes to 1 and calculating the multiplicity of that "end" of the association according to the requirements.
- Ternary = 3 classes involved; Quaternary = 4 classes; n-ary = n classes...
.center[.imgscaledup[]]
---
name: nary_association_classes
## N-ary Association Classes
- Association classes can also be associated to n-ary associations.
- Attributes need to depend on all of the associated classes!
.center[.imgscaledup[]]
---
name: constraints
## Constraints
- Used to specify conditions that must be met by the system
- Denoted by SQL-like text between brackets `{}`, either close to the relevant class (or classes) or connected by a dashed line to those elements
.center[.imgscaledup[]]
---
name: derived_elements
## Derived Elements
- Elements (classes, attributes or associations) that are computed from information that already exists in other elements.
- Notation: `/` before the name of the derived element.
- Derived elements usually have an associated constraint that specifies how it is calculated.
- They add complexity to the diagram, so should be used sparingly to highlight important pre-computed attributes, associations or classes.
---
name: derived_attributes
## Derived Attributes
- Can be used to highlight a frequently used element that is expensive to compute
- Indicate the need to pre-compute an attribute and save it in the system, as it will be typically read many times but written only a few
.center[.imgscaledup[]]
---
name: derived_associations
.no-top-margin[
## Derived Associations
]
- Similar to derived attributes, but express associations that result of computation
- Expensive to compute: perform an expensive computation and save the result once on certain changes to the system (i.e. when a new `Order` is added for a `Client`, recompute the `mostPurchasedProduct` and save it).
- Then just read the `mostPurchasedProduct` instantly many times, without having to re-compute.
.center[.imgscaledup[]]
---
name: derived_classes
## Derived Classes
- Classes computed from other elements in the system
- Same logic as the other derived elements
.center[.imgscaledup[]]
---
name: software
## Useful Software
For building UML diagrams:
- [diagrams.net](https://diagrams.net) - Free online collaborative diagramming (has integration with Google Drive)
- [Lucidchart](https://www.lucidchart.com) - Free online collaborative diagramming (has integration with Google Drive)
- [Dia](http://dia-installer.de) - Free offline diagramming for all operating systems
---
name: references
## References
- *Jeffrey D. Ullman and Jennifer Widom. 2008. A First Course in Database Systems. 3rd Edition*
- Section 4.7 Unified Modeling Language
- *CS145 Lecture Notes (7) -- Higher-Level Design: UML. [Link](http://infolab.stanford.edu/~ullman/fcdb/jw-notes06/uml.html).*