Unified Modeling Language (UML)
- the two primary diagrams: **static** (Class diagrams) and **object interaction** (Sequence diagrams).
- These tools are essential for visualizing, specifying, constructing, and documenting the artifacts of software systems.
## 1. Static (Class) Diagrams
### 1.1 Introduction
- Class diagrams are the most common diagrams used in UML.
- They show the static structure of the system, emphasizing classes, attributes, operations, and relationships.
### 1.2 Components of a Class Diagram
1. **Class**: Represented by a rectangle, divided into three parts:
- Class name
- Operations (methods)
2. **Relationships**: Represented using different types of lines.
- **Association**: A plain line.
- **Aggregation**: A diamond line pointing to the whole.
- **Composition**: A filled diamond line pointing to the whole.
- **Inheritance**: A line with a triangle arrow pointing to the base class.
### 1.3 Exercise: Sketch a Class Diagram
**Scenario**: Model a simple library system.
- Attributes: title, author, ISBN.
- Operations: checkout(), returnBook().
- Attributes: name, memberID.
- Operations: borrowBook(), returnBook().
3. A **Member** can borrow multiple **Books**, but a **Book** can be borrowed by one **Member** at a time.
**Task**: Draw the class diagram based on the above description.
> [Expect students to draft a sketch. Discuss different versions and fine-tune the class relationships.]
## 2. Object Interaction (Sequence) Diagrams
### 2.1 Introduction
- Sequence diagrams display the dynamic interactions between objects.
- They emphasize the sequence of messages exchanged between objects over time.
### 2.2 Components of a Sequence Diagram
1. **Object**: Represented by a rectangle at the top.
2. **Activation Bar**: Thin rectangles that show an object's period of activity.
3. **Messages**: Horizontal arrows representing communication between objects.
4. **Return Message**: Dashed horizontal arrows indicating the return of a message.
5. **Lifeline**: Dashed vertical line representing the object's existence.
### 2.3 Exercise: Sketch a Sequence Diagram
**Scenario**: Depict how a `Member` borrows a `Book` from a `Library`.
1. The `Member` requests a `Book`.
2. The `Library` checks if the `Book` is available.
3. If available, the `Library` processes the borrowing.
4. The `Book` is marked as borrowed, and the `Library` sends a confirmation to the `Member`.
**Task**: Draw the sequence diagram based on the above interactions.
> [Expect students to draft a sketch. Discuss different sequence representations and the order of messages.]
## Closing Thoughts
UML diagrams are powerful tools to represent complex systems. Mastering them will help you design, communicate, and understand software projects more effectively.
For your homework, please model a new system of your choice using both a static class diagram and an object interaction sequence diagram.