UML Diagram Scenarios
UML Diagram Scenarios
UML diagrams:
Situation: Aisha's professor has tasked the class with conceptualizing the database schema
for "BookWorm Rentals," a system where students can rent textbooks for a semester. The
system needs to track textbooks, students, rentals, and overdue books. Aisha realizes she can't
jump straight into SQL tables. She needs to understand the core data elements and their
relationships first to ensure data integrity and avoid redundancy.
Why an ERD is needed: An ERD is the perfect tool for Aisha to visually represent the
entities (e.g., Student, Textbook, Rental), their attributes (e.g., studentID, textbookISBN,
rentalDate), and the relationships between them (e.g., "A Student rents a Textbook," "A
Textbook can be included in multiple Rentals"). This will help her identify primary and
foreign keys, understand cardinality (one-to-many, many-to-many), and ultimately design a
robust and efficient database. She'll be able to answer questions like: "Can a textbook be
rented by multiple students simultaneously?" or "Does a student need to exist in the system
before renting a book?"
Situation: Ben is working on the "CampusEats" app. He's at the stage where he needs to
clearly define how a user places an order, from selecting items to receiving confirmation.
Multiple components are involved: the mobile app frontend, the backend API, the restaurant's
system, and a payment gateway. Ben needs to visualize the flow of messages and interactions
between these different parts to ensure smooth operation and identify potential
communication bottlenecks.
Why a Sequence Diagram is needed: A Sequence Diagram will allow Ben to illustrate the
chronological order of messages exchanged between objects or actors within the "Place
Order" use case. He can show:
The user interacting with the mobile app (e.g., User -> Mobile App:
selectFoodItem())
The app communicating with the backend (e.g., Mobile App -> Backend API:
submitOrderRequest())
The backend interacting with the payment gateway (e.g., Backend API -> Payment
Gateway: processPayment())
And finally, the confirmation sent back to the user (e.g., Backend API -> Mobile
App: sendOrderConfirmation()).
This diagram will be crucial for him to discuss the interaction flow with his team, identify
potential race conditions, and refine the API calls.
Situation: Chloe is tasked with developing a system that allows librarians to manage books
and members. She knows she needs to use object-oriented principles, but she's struggling to
define the different "types" of things in her system (e.g., a book, a member, a loan) and how
they relate to each other in terms of attributes and behaviors. She's getting confused about
which data belongs to which object and how they should interact.
Why a Class Diagram is needed: A Class Diagram is essential for Chloe to model the static
structure of her system. She can define classes like Book (with attributes like title, author,
ISBN), Member (with attributes like memberID, name, contactInfo), and Loan (with attributes
like loanDate, dueDate). More importantly, she can define the relationships between these
classes (e.g., "A Member can borrow multiple Books," "A Book can be part of many
Loans"). She can also define methods (behaviors) for each class (e.g., Book: checkout(),
Member: register(), Loan: renew()). This diagram will clarify her object model, promote
proper encapsulation, and serve as a blueprint for her Java code.
Situation: David's first major assignment is to understand and document the functionalities
of a new online movie streaming service, "StreamFlix." He needs to identify who will use the
system and what they will be able to do. He's overwhelmed by all the potential features
(Browse, searching, subscribing, watching, reviewing, parental controls, etc.) and needs a
high-level overview before diving into detailed design.
Why a Use Case Diagram is needed: A Use Case Diagram is the perfect starting point for
David. It will allow him to identify the main actors (e.g., Registered User, Guest User,
Administrator, Payment Processor) and the high-level functionalities (use cases) they can
perform with the system. He can draw use cases like:
Browse Movies
Search for Movie
Stream Movie
Subscribe to Service
Manage Profile
Add Movie (Administrator)
He can also show relationships between use cases, such as <<include>> (e.g., Stream Movie
includes Authenticate User) or <<extend>> (e.g., Stream Movie extends to Rate Movie).
This diagram will provide a clear, concise overview of the system's scope and functionalities
from the user's perspective, helping him to organize his thoughts and communicate the
system's requirements effectively to his instructors and potential stakeholders.
Code snippet
erDiagram
STUDENT ||--o{ RENTAL : "rents"
TEXTBOOK ||--o{ RENTAL : "is_part_of"
RENTAL ||--o{ OVERDUE_CHARGE : "generates"
STUDENT {
VARCHAR studentID PK
VARCHAR firstName
VARCHAR lastName
VARCHAR email UNIQUE
VARCHAR phoneNumber
}
TEXTBOOK {
VARCHAR textbookID PK
VARCHAR title
VARCHAR author
VARCHAR ISBN UNIQUE
DECIMAL rentalPricePerSemester
INT quantityAvailable
}
RENTAL {
VARCHAR rentalID PK
VARCHAR studentID FK
VARCHAR textbookID FK
DATE rentalDate
DATE dueDate
DATE returnDate
BOOLEAN isReturned
}
OVERDUE_CHARGE {
VARCHAR chargeID PK
VARCHAR rentalID FK
DECIMAL amount
DATE chargeDate
BOOLEAN isPaid
}
Entities (Rectangles):
o STUDENT: Represents a university student using the platform.
o TEXTBOOK: Represents a textbook available for rent.
o RENTAL: Represents a specific instance of a student renting a textbook. This is an
associative entity as it connects STUDENT and TEXTBOOK and has its own attributes
(like rentalDate and dueDate).
o OVERDUE_CHARGE: Represents a charge incurred when a rental is returned late.
This ERD provides a clear conceptual model for Aisha, allowing her to visualize the database
structure before moving on to the logical and physical design in SQL.