uml
uml
Definition of UML
UML (Unified Modeling Language) is a visual language for modeling and
documenting the design of software systems.
Example:
For an online bookstore:
Actors: Customer, Admin
Use Cases: Browse Books, Purchase Book, Manage Inventory
System Boundary: Enclose the use cases in a rectangle labeled “Online
Bookstore”
Connections:
Customer → Browse Books, Purchase Book
Admin → Manage Inventory
Use Cases:
Role: Functions or services the system provides.
Example: Browse Books, Purchase Book
System Boundary:
Role: Defines what is inside (use cases) and outside (actors) of the system.
Example: A rectangle labeled “Online Bookstore”
Relationships:
Include: One use case uses the functionality of another.
Example: Purchase Book «include» Process Payment
Extend: One use case adds extra behavior to another.
Example: Purchase Book «extend» Apply Discount
Generalization: One actor or use case inherits behavior from another.
Example: Premium Customer generalizes Customer
2. Attributes:
Role: Characteristics or properties of classes.
Example: `title` and `author` for the `Book` class.
3. Methods:
Role: Functions or behaviors of classes.
Example: `borrow()`, `return()` for the `Book` class.
4. Relationships:
Associations: Show connections between classes.
Example: A `Library` has many `Books`.
Generalizations: Indicate inheritance between classes.
Example: `Ebook` generalizes `Book`.
Dependencies: Show that one class uses another.
Example: A `Member` class depends on the `Book` class for borrowing
books.
5. Multiplicity:
Role: Specifies the number of instances in a relationship.
Example: A `Library` (1) can have many `Books` (1..*).
Example:
A class diagram for a library system might include:
Classes: `Library`, `Book`, `Member`
Attributes: `Book` (title, author), `Member` (name, memberID)
Methods: `Book` (borrow(), return()), `Member` (register(), borrowBook())
Relationships: `Library` (1) — (1..*) `Book`, `Member` (1..*) — (0..*) `Book`
2. Attributes:
Role: Define properties or characteristics of a class.
Example: `title`, `author` for the `Book` class.
3. Methods:
Role: Define behaviors or functions of a class.
Example: `borrow()`, `return()` for the `Book` class.
4. Relationships:
Associations: Show how classes are connected.
Example: `Library` has `Books`.
Generalizations: Represent inheritance.
Example: `Ebook` generalizes `Book`.
Dependencies: Show that one class uses another.
Example: `Member` depends on `Book` to borrow books.
5. Multiplicity:
Role: Indicates the number of instances in a relationship.
Example: A `Library` (1) can have many `Books` (1..*).
These elements are crucial for accurately representing and understanding the
structure and relationships within a system using UML class diagrams.
Sequence diagram
A Sequence Diagram shows how objects interact in a scenario by representing
the order of messages exchanged between them.
Key Elements
1. Objects (Lifelines):
Role: Represent participants.
Example: `User`, `LoginPage`, `AuthService`.
Diagram: Vertical dashed lines with object names.
2. Messages:
Role: Show communication.
Types:
Synchronous: Sender waits for response.
Asynchronous: Sender doesn’t wait.
Return: Receiver responds.
Example: `User` → `AuthService`: loginRequest()
3. Activation Bars:
Role: Show object’s activity.
Diagram: Thin rectangles on lifelines during processing.
4. Combined Fragments:
Role: Show control structures.
Types:
alt: Conditional branches.
loop: Repeated actions.
opt: Optional actions.
# Objects:
`User`
`LoginPage`
`AuthService`
# Messages:
1. User → `enterCredentials()` → LoginPage
2. LoginPage → `authenticate()` → AuthService
3. AuthService → `authenticationResult()` → LoginPage
4. LoginPage → `displayResult()` → User
# Diagram:
1. User → `enterCredentials()` → LoginPage
2. LoginPage → `authenticate()` → AuthService
3. AuthService → `authenticationResult()` → LoginPage
4. LoginPage → `displayResult()` → User
This diagram simplifies the interaction flow for a user login, showing the order of
messages exchanged between objects.
Activity Diagram
An Activity Diagram in UML shows the flow of activities or tasks within a
system.
Key Elements
1. Activity (Action):
Represents a task or action.
Example: `Login`, `Browse Products`, `Checkout`.
6. Initial Node:
Indicates the starting point.
Example: Start of the order process.
7. Final Node:
Indicates the ending point.
Example: End of the order process.
Component diagram
A Component Diagram in UML shows the components and their relationships in
a system.
Key Elements
1. Component:
Represents a part of the system with defined functionality.
Example: `User Interface`, `Database`, `Payment System`.
2. Interface:
Describes how components interact with each other.
Example: `Database Interface`, `Payment Interface`.
3. Dependency:
Shows that one component relies on another.
Example: `User Interface` depends on `Database`.
1. Components:
`User Interface`
`Database`
`Payment System`
2. Interfaces:
`User Interface`: Communicates with users.
`Database`: Accesses data.
`Payment System`: Handles payments.
3. Dependencies:
`User Interface` depends on `Database`.
`Payment System` relies on `Database`.