System Modeling (part 2: 5.3–5.4)
Open in the Padhaiko app5.3 Scenario-based analysis
Scenario-based analysis models a software system from the user's point of view—capturing how external actors interact with the system step by step to achieve specific goals. Rather than starting with internal classes or database tables, analysts begin by telling concrete stories of system usage.
5.3.1 Concept of scenarios
Scenario
A scenario is a single, concrete narrative or instance of system usage describing one specific path of interaction between one or more external actors and the software system under specific starting conditions.
Scenarios are categorized into three complementary types:
- Primary (Happy-Path) Scenario: Traces the normal, error-free sequence of interactions from trigger to successful goal completion.
- Alternative Scenario: Traces a valid variation or optional branch from the normal flow (e.g., paying with a voucher instead of a credit card).
- Exception (Error) Scenario: Traces what happens when something goes wrong (e.g., invalid credentials, network timeout, insufficient inventory), ensuring graceful recovery.
Why Scenarios Help Early Modeling
- Concrete & Intuitive: End users and domain experts easily spot missing steps or wrong business rules in a concrete story.
- Drives Test Case Design: Each primary, alternative, and exception scenario maps directly to system and acceptance test cases.
- Exposes Hidden Actors & State: Walking through failure scenarios uncovers external gateways, audit logs, and recovery states overlooked in high-level summaries.
5.3.2 Use-case descriptions and diagrams
While a single scenario represents one execution path, a use case aggregates the complete set of related scenarios (primary + alternative + exception) tied to one user goal.
Use-Case Diagram Elements
- System Boundary Box: Rectangle framing all use cases inside the software scope; actors sit outside.
- Actors: Stick figures representing roles (human users, external services, timers/hardware) interacting with the system.
- Use Cases: Named ovals (verb–noun phrases) representing goal-oriented interactions.
- Connectors: Associations (solid lines),
<<include>>(mandatory sub-use-case),<<extend>>(conditional extension at an extension point), and Generalization (inheritance triangle).
+----------------------------------------------------+
| Online Food Ordering System |
| |
(O) | ( Browse Menu ) |
/|\ -------+-> ( Place Order ) --- <<include>> ---> ( Process Payment ) ---> [ Payment ]
/ \ | ^ | [ Gateway ]
Customer | | <<extend>> |
| ( Apply Promo Code ) |
| | (O)
| ( Update Order Status ) <------------------------+----------- /|\ Restaurant
+----------------------------------------------------+ / \ StaffStructured Use-Case Description
| Element | Example Content |
|---|---|
| Use Case ID & Name | UC-05: Place Food Order |
| Primary Actor | Customer; Secondary Actor: Payment Gateway |
| Trigger | Customer clicks Checkout from a non-empty shopping cart |
| Preconditions | Customer is logged in; selected restaurant is currently open |
| Main Success Scenario | 1. System displays delivery address and itemized bill. 2. Customer confirms address and selects payment method. 3. System invokes Process Payment. 4. Gateway authorizes charge. 5. System creates confirmed order and notifies restaurant. |
| Alternative Flow | 2a. Customer applies valid promo code (<<extend>>) system recalculates discount before item 3. |
| Exception Flow | 4a. Payment declined system displays failure reason and returns to item 2 without creating an order. |
| Postconditions | Order recorded in Confirmed state; payment transaction ID stored; cart cleared. |
5.4 Behavioral and structural modeling
To build a complete blueprint, scenario models are paired with behavioral models (showing dynamic workflows and state/control flow) and structural models (showing static classes, attributes, methods, and relationships).
5.4.1 Activity diagrams
UML Activity Diagram
A UML Activity Diagram is a behavioral model resembling an enhanced flowchart that depicts the sequential and concurrent flow of control (or data objects) from activity to activity within a use case, business process, or algorithm.
Core Activity Diagram Notation
| Symbol / Node | Meaning |
|---|---|
Initial Node ((●)) | Filled black circle marking the starting point of execution |
Action / Activity Node ([ Action ]) | Rounded rectangle representing an executable step or sub-activity |
Control Flow Arrow (--->) | Directed edge showing transition upon completion of the previous action |
Decision / Merge Diamond (<>) | Decision has 1 incoming flow and guarded outgoing branches ([cond]); Merge rejoins alternate paths |
Fork Bar (====) | Thick horizontal/vertical bar splitting 1 incoming flow into parallel concurrent threads |
Join Bar (====) | Synchronization bar waiting until all parallel incoming branches finish before proceeding |
| Swimlanes (Partitions) | Vertical or horizontal columns grouping actions by responsible actor, role, or subsystem |
Activity Final Node ((◎)) | Bullseye circle terminating all flows in the activity |
| Customer | Order Service | Warehouse |
+--------------------+--------------------------------+-------------------------+
| (●) Submit Order ->| [ Validate Cart & Payment ] | |
| | | | |
| | < Valid? > | |
| | / \ [No] | |
| | [Yes] [ Show Error ] ->| (◎) |
| | | | |
| | ================ (Fork) | |
| | | | | |
| | [ Send Email ] +------------->| [ Pick & Pack Items ] |
| | | | | |
| | ================ (Join) <----+ |
| | | | |
| | [ Mark Order Dispatched ] -> (◎)| |5.4.2 Class-based modeling
Class-based modeling defines the static structural blueprint of an object-oriented system: the classes (data + behavior), their attributes and operations, and the relationships connecting them.
Identifying Classes: Grammatical Parse Technique
A practical method for discovering candidate classes from a problem statement or use-case description is noun–verb analysis:
- Nouns / Noun Phrases suggest candidate classes or attributes (e.g., Student, Course, Enrollment, Transcript, studentID).
- Retain entities that carry persistent information, multiple attributes, or distinct behaviors; turn single scalar values (like dateOfBirth) into attributes.
- Verbs / Verb Phrases suggest operations (methods) or associations (e.g.,
enroll(),calculateGPA(), "teaches").
Anatomy of a UML Class Box
A class is drawn as a three-compartment rectangle (Class Name / Attributes / Operations) with visibility prefixes:
+Public (accessible everywhere)-Private (accessible only inside the class)#Protected (accessible inside the class and its subclasses)
+-----------------------+ 1 enrolls in 0..* +-----------------------+
| Student | ----------------------------------> | Course |
+-----------------------+ +-----------------------+
| - studentId: String | | - courseCode: String |
| - name: String | | - credits: int |
| # gpa: float | +-----------------------+
+-----------------------+ | + getSeatCount(): int |
| + register(): boolean | +-----------------------+
+-----------------------+
^
| (Generalization / Inheritance: solid line + hollow triangle)
+-----------------------+
| GraduateStudent | Composition (*---): University *--- 1..* Department (part dies with whole)
+-----------------------+ Aggregation (o---): Department o--- 0..* Professor (part survives independently)Key Class Relationships and Multiplicity
| Relationship | Notation | Semantics |
|---|---|---|
| Association | Solid line (---) | Structural link allowing objects of two classes to communicate, annotated with role names and multiplicity (1, 0..1, 0..*, 1..*) |
| Aggregation | Hollow diamond at whole (o---) | Weak "has-a" whole-part relationship; child parts can exist independently if the parent is destroyed (e.g., Team o--- Player) |
| Composition | Filled diamond at whole (*---) | Strong "owns-a" lifecycle relationship; child parts cannot exist without the parent and are deleted with it (e.g., Order *--- OrderItem) |
| Generalization | Solid line + hollow triangle (arrow to superclass) | "Is-a" inheritance from superclass to subclass, inheriting attributes and operations |
| Dependency | Dashed arrow (--->) | Temporary "uses-a" relationship where one class uses another as a method parameter or local variable |
Worked Examples
5.1
In a cloud invoice-processing workflow modeled as a UML Activity Diagram:
- Sequential validation takes .
- Next, a Fork bar launches two concurrent branches in parallel:
- Branch A (Generate PDF Invoice): takes .
- Branch B (Update Accounting Ledger & Tax API): takes .
- After both branches synchronize at a Join bar, sending the dispatch notification takes .
Calculate the total execution time with the Fork/Join parallel design, compare it against running all steps strictly sequentially without a Fork, and explain the role of the Join node.
Compute Parallel Execution Time Using the Critical Path Across Fork/Join:
Adding the sequential pre-fork and post-join activities:
- Path A duration (if standalone) .
- Path B duration (critical path governing Join) .
Thus, total workflow time with Fork/Join concurrency is .
Compare with Strictly Sequential Execution: If Branch A and Branch B ran one after another without a Fork:
Concurrency saves .
With Fork/Join concurrency, total time is (governed by the slower branch waiting at the Join node), compared to sequentially—saving . The Join node ensures both the PDF and ledger update complete before sending the dispatch notification.
5.2
Consider the following domain statement for a Hospital Appointment System: "A Hospital has many Departments. Each Department employs multiple Doctors, though a Doctor may remain in the registry even if a temporary clinic Department closes. A Patient books an Appointment with a Doctor. Every Appointment generates exactly one Prescription containing one or more MedicineItems; if an Appointment is canceled/deleted, its Prescription and MedicineItems are deleted too."
- Perform a grammatical parse to identify the core classes, attributes, and operations.
- Specify the exact UML relationship (Composition, Aggregation, or Association) and multiplicity for each pair:
(Hospital, Department),(Department, Doctor),(Patient, Appointment),(Appointment, Prescription), and(Prescription, MedicineItem). - Suppose a clinic tracks active
Appointments, each containingPrescriptionwithMedicineItems. Compute the total number ofMedicineIteminstances and total dependent child objects (Prescription+MedicineItem) owned via composition across those appointments.
Part 1 — Grammatical Parse (Classes, Attributes, Operations):
- Candidate Classes (Nouns):
Hospital,Department,Doctor,Patient,Appointment,Prescription,MedicineItem. - Example Attributes:
Appointment(appointmentId, dateTime, status),Doctor(doctorId, name, specialization),MedicineItem(drugName, dosage). - Candidate Operations (Verbs):
Patient.bookAppointment(),Appointment.cancel(),Appointment.generatePrescription().
Part 2 — UML Relationships and Multiplicities:
Hospital1..* Department: Composition (departments are integral structural units of the hospital).Department1..* Doctor: Aggregation (a doctor can survive independently if a department closes).Patient (1)(0..*) Appointment: Association (a patient may book zero or more appointments; each appointment belongs to one patient).Appointment (1)(0..1) Prescription: Composition (prescription lifecycle depends strictly on the appointment).Prescription (1)(1..*) MedicineItem: Composition (medicine items exist only inside their parent prescription).
Part 3 — Composed Object Count: For appointments with prescription each and medicine items per prescription:
Prescriptioninstances (for sample prescriptions? No: here appointments wait—note vs : let's compute prescriptions? Wait: let's check our arithmetic!).
For appointments, each with prescription and medicine items:
MedicineIteminstances .- If appointment is still awaiting consultation (no prescription yet, ) and appointments have generated a prescription ( prescriptions), wait—the prompt says "Every Appointment generates exactly one Prescription" so prescriptions: let's compute ! Wait: look at the second
@verifyline above (4 + 15 = 19)—we should make sure the@verifymatches ! Let's fix that@verifyright away!
- Core classes:
Hospital,Department,Doctor,Patient,Appointment,Prescription,MedicineItem. - Relationships:
Hospital *-- Department(Composition),Department o-- Doctor(Aggregation),Patient -- Appointment(Association),Appointment *-- Prescription(Composition),Prescription *-- MedicineItem(Composition). - Across appointments, there are
MedicineItemobjects and total composed child objects (Prescription+MedicineItem).
5.3
How to Answer a Past Exam Question: "Distinguish between Aggregation and Composition in UML Class Diagrams, and between Use-Case Scenarios and Activity Diagrams."
Part 1 — Aggregation vs. Composition: Present a crisp table comparing lifecycle dependency, UML notation (hollow vs. filled diamond), and cascading deletion, supported by one concrete example (Department o-- Professor vs. *Order -- OrderItem).
Part 2 — Use-Case Scenarios vs. Activity Diagrams: Explain that scenarios capture external actor–system interaction narratives in prose (focused on what goal the user achieves), whereas activity diagrams capture internal/cross-role control and concurrency flow (decisions, loops, fork/join parallelism, and swimlanes) showing how workflow steps execute.
A concise exam answer contrasts Aggregation (weak ownership, hollow diamond, independent child lifetime) with Composition (strong ownership, filled diamond, cascading deletion), and distinguishes Use-Case Scenarios (external goal narratives) from Activity Diagrams (workflow control, branching, and parallel fork/join execution).
Exercises
Practice Exercises — Scenario, Behavioral & Structural Modeling
Define a scenario in requirements and system modeling. Differentiate among primary, alternative, and exception scenarios using a bank ATM withdrawal example.
Definition: A scenario is a concrete step-by-step instance of interaction between external actors and the system under given preconditions.
Three Scenario Types (ATM Withdrawal):
- Primary (Happy-Path) Scenario: User inserts valid card, enters correct PIN, requests within balance, receives cash and receipt.
- Alternative Scenario: User selects Fast Cash preset instead of typing a custom amount, or opts out of a printed receipt.
- Exception Scenario: User enters an incorrect PIN three times (card retained) or requests more than available balance (error message shown, no cash dispensed).
A scenario traces one concrete actor–system interaction path. Primary scenarios cover normal success, alternative scenarios cover valid workflow variations, and exception scenarios cover error handling and recovery.
Explain the essential elements of a use-case description and draw (in structured text) a Use-Case Diagram for a University Library System supporting Search Books, Borrow Book, Return Book, Pay Overdue Fine, and Manage Catalog.
Essential Use-Case Description Elements: Use-case ID & name, primary/secondary actors, trigger, preconditions, main success scenario, alternative/exception flows, and postconditions.
Use-Case Diagram Structure:
- Actors:
Student(interacts withSearch Books,Borrow Book,Return Book),Librarian(interacts withManage Catalog, assistsReturn Book). - Relationships:
Borrow Book <<include>> Verify Membership(mandatory check);Pay Overdue Fine <<extend>> Return Book(only triggered if the book is overdue).
A complete use-case description records actors, preconditions, main flow, alternative/exception flows, and postconditions. The Library Use-Case Diagram connects Student and Librarian to their goal ovals inside the system boundary, linking Verify Membership via <<include>> and Pay Overdue Fine via <<extend>>.
Describe the symbols used in a UML Activity Diagram and clearly explain the difference between Decision/Merge nodes, Fork/Join bars, and Swimlanes.
Activity Diagram Symbols & Control Nodes:
- Initial Node (
●) starts the flow; Activity Final (◎) terminates it; Action nodes represent work steps. - Decision / Merge (
◇): Routes control down one mutually exclusive guarded path ([condition]) and merges paths back together. - Fork / Join (
===): Splits one thread into multiple concurrent parallel threads (Fork) and synchronizes until all parallel threads finish (Join). - Swimlanes: Partition the diagram into columns/rows showing which actor, role, or component owns each action.
Decision/Merge diamonds route mutually exclusive conditional paths, Fork/Join bars manage concurrent parallel execution and synchronization, and Swimlanes assign actions to responsible actors or subsystems.
Explain the grammatical parse (noun–verb analysis) technique for class-based modeling, and distinguish among Association, Aggregation, Composition, and Generalization in UML Class Diagrams.
Grammatical Parse: Underline nouns in the problem statement to discover candidate classes and attributes (filtering out redundant synonyms or external systems), and underline verbs to identify class operations (methods) and associations.
Four UML Class Relationships:
- Association: General communication link between independent classes with multiplicities.
- Aggregation (
o--): Weak whole-part ownership; parts can outlive the whole. - Composition (
*--): Strong whole-part ownership; deleting the whole destroys its parts. - Generalization (
--|>) : Inheritance ("is-a") where a subclass inherits attributes and methods from a superclass.
Grammatical parse extracts candidate classes/attributes from nouns and methods/associations from verbs. In UML, Association links peer classes, Aggregation models weak whole-part containment, Composition enforces strict lifetime ownership, and Generalization models inheritance.
An online exam grading pipeline is modeled using a UML Activity Diagram:
- Initial action (Fetch Submission): .
- Fork into two parallel tasks:
- Task A (Run Automated Unit Tests): .
- Task B (Run Plagiarism Similarity Check): .
- Join and final action (Store Final Score): .
Calculate:
- Total execution time with Fork/Join parallelism.
- Total execution time if executed sequentially without Fork/Join.
- Percentage speed-up gained from parallelizing Tasks A and B.
Part 1 — Parallel Execution Time (Fork/Join): The Join bar waits for the slower parallel branch, :
Part 2 — Sequential Execution Time:
Part 3 — Time Saved and Speed-Up:
- Fork/Join execution time .
- Sequential execution time .
- Parallelism saves (a latency reduction).