PadhaikoAll subjects

System Modeling (part 2: 5.3–5.4)

Software Engineering (ENCT 352)

Open in the Padhaiko app

5.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

Definition

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:

  1. Primary (Happy-Path) Scenario: Traces the normal, error-free sequence of interactions from trigger to successful goal completion.
  2. Alternative Scenario: Traces a valid variation or optional branch from the normal flow (e.g., paying with a voucher instead of a credit card).
  3. 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

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

  1. System Boundary Box: Rectangle framing all use cases inside the software scope; actors sit outside.
  2. Actors: Stick figures representing roles (human users, external services, timers/hardware) interacting with the system.
  3. Use Cases: Named ovals (verb–noun phrases) representing goal-oriented interactions.
  4. Connectors: Associations (solid lines), <<include>> (mandatory sub-use-case), <<extend>> (conditional extension at an extension point), and Generalization (inheritance triangle).
Use-Case Diagram: Online Food OrderingText
              +----------------------------------------------------+
              |             Online Food Ordering System            |
              |                                                    |
   (O)        |   ( Browse Menu )                                  |
   /|\ -------+-> ( Place Order ) --- <<include>> ---> ( Process Payment ) ---> [ Payment ]
   / \        |         ^                                          |            [ Gateway ]
Customer      |         | <<extend>>                               |
              |   ( Apply Promo Code )                             |
              |                                                    |            (O)
              |   ( Update Order Status ) <------------------------+----------- /|\  Restaurant
              +----------------------------------------------------+            / \  Staff

Structured Use-Case Description

Detailed Use-Case Description Format (UC-05: Place Order)
ElementExample Content
Use Case ID & NameUC-05: Place Food Order
Primary ActorCustomer; Secondary Actor: Payment Gateway
TriggerCustomer clicks Checkout from a non-empty shopping cart
PreconditionsCustomer is logged in; selected restaurant is currently open
Main Success Scenario1. 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 Flow2a. Customer applies valid promo code (<<extend>>) system recalculates discount before item 3.
Exception Flow4a. Payment declined system displays failure reason and returns to item 2 without creating an order.
PostconditionsOrder 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

Definition

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

Standard UML Activity Diagram Elements
Symbol / NodeMeaning
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
Activity Diagram with Fork/Join Concurrency and Swimlanes: Order FulfillmentText
|      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:

  1. 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.
  2. 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:

UML Class Notation and RelationshipsText
+-----------------------+          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

UML Class Diagram Relationships
RelationshipNotationSemantics
AssociationSolid line (---)Structural link allowing objects of two classes to communicate, annotated with role names and multiplicity (1, 0..1, 0..*, 1..*)
AggregationHollow 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)
CompositionFilled diamond at whole (*---)Strong "owns-a" lifecycle relationship; child parts cannot exist without the parent and are deleted with it (e.g., Order *--- OrderItem)
GeneralizationSolid line + hollow triangle (arrow to superclass)"Is-a" inheritance from superclass to subclass, inheriting attributes and operations
DependencyDashed arrow (--->)Temporary "uses-a" relationship where one class uses another as a method parameter or local variable

Worked Examples

Example 5.1

5.1

In a cloud invoice-processing workflow modeled as a UML Activity Diagram:

  1. Sequential validation takes .
  2. Next, a Fork bar launches two concurrent branches in parallel:
    • Branch A (Generate PDF Invoice): takes .
    • Branch B (Update Accounting Ledger & Tax API): takes .
  3. 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 .

Answer:

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.

Example 5.2

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."

  1. Perform a grammatical parse to identify the core classes, attributes, and operations.
  2. 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).
  3. Suppose a clinic tracks active Appointments, each containing Prescription with MedicineItems. Compute the total number of MedicineItem instances 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:

  • Hospital 1..* Department: Composition (departments are integral structural units of the hospital).
  • Department 1..* 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:

  • Prescription instances (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:

  • MedicineItem instances .
  • 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 @verify line above (4 + 15 = 19)—we should make sure the @verify matches ! Let's fix that @verify right away!
Answer:
  1. Core classes: Hospital, Department, Doctor, Patient, Appointment, Prescription, MedicineItem.
  2. Relationships: Hospital *-- Department (Composition), Department o-- Doctor (Aggregation), Patient -- Appointment (Association), Appointment *-- Prescription (Composition), Prescription *-- MedicineItem (Composition).
  3. Across appointments, there are MedicineItem objects and total composed child objects ( Prescription + MedicineItem).
Example 5.3

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.

Answer:

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

Question 1

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):

  1. Primary (Happy-Path) Scenario: User inserts valid card, enters correct PIN, requests within balance, receives cash and receipt.
  2. Alternative Scenario: User selects Fast Cash preset instead of typing a custom amount, or opts out of a printed receipt.
  3. Exception Scenario: User enters an incorrect PIN three times (card retained) or requests more than available balance (error message shown, no cash dispensed).
Answer:

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.

Question 2

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 with Search Books, Borrow Book, Return Book), Librarian (interacts with Manage Catalog, assists Return Book).
  • Relationships: Borrow Book <<include>> Verify Membership (mandatory check); Pay Overdue Fine <<extend>> Return Book (only triggered if the book is overdue).
Answer:

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>>.

Question 3

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.
Answer:

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.

Question 4

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.
Answer:

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.

Question 5

An online exam grading pipeline is modeled using a UML Activity Diagram:

Calculate:

  1. Total execution time with Fork/Join parallelism.
  2. Total execution time if executed sequentially without Fork/Join.
  3. 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:

Answer:
  1. Fork/Join execution time .
  2. Sequential execution time .
  3. Parallelism saves (a latency reduction).
← System Modeling (part 1: 5.1–5.2)Coding and Testing →