IT242 Software Design and Development

Software Design and DevelopmentUnit 410 min read

UML Modelling: Diagrams, Use Cases & Class Design

Unit 4 of Software Design and Development covers Unified Modeling Language (UML)—its 14 diagrams, use case analysis, class diagrams, sequence diagrams, and activity diagrams—with real-world applications in Nepalese software (eSewa, Daraz) and exam-focused techniques.

TAKEAWAYS:

  • UML provides 14 standardized diagrams (7 structural, 7 behavioral) to model software systems visually.
  • Use case diagrams capture user interactions with the system (e.g., Daraz’s "Place Order" workflow).
  • Class diagrams define objects, attributes, and relationships (e.g., Ncell’s "Customer" ↔ "Subscription" link).
  • Sequence diagrams show message flows between objects (e.g., WhatsApp’s "Send Message" handshake).
  • Activity diagrams model workflows (e.g., Khalti’s "Payment Approval" process).
  • Exam tip: Always label relationships (<<extends>>, <<realizes>>) and include multiplicity (1..*, 0..1).

What is UML?

Unified Modeling Language (UML) is a standardized visual language for designing, documenting, and communicating software systems. Developed in 1997 by Grady Booch, Ivar Jacobson, and James Rumbaugh, UML is used in 90% of enterprise software projects (IBM, Oracle, and Nepalese banks like NMB use it for core systems).

Why Use UML?

  • Clarity: Replaces ambiguous text descriptions with precise diagrams.
  • Reusability: Models can be reused across projects (e.g., Daraz’s inventory system).
  • Communication: Bridges gaps between developers, testers, and clients (e.g., NTC’s billing software).
  • Standardization: Ensures consistency in design (ISO/IEC 19501-2005).

The 14 UML Diagrams

UML divides diagrams into two categories:

  1. Structural Diagrams (show static relationships).
  2. Behavioral Diagrams (show dynamic interactions).
mindmap
  root((UML Diagrams))
    Structural
      Class["Class Diagram"]
      Object["Object Diagram"]
      Component["Component Diagram"]
      Deployment["Deployment Diagram"]
      Package["Package Diagram"]
      Profile["Profile Diagram"]
      Composite Structure["Composite Structure Diagram"]
    Behavioral
      Use Case["Use Case Diagram"]
      Activity["Activity Diagram"]
      State["State Machine Diagram"]
      Sequence["Sequence Diagram"]
      Communication["Communication Diagram"]
      Interaction Overview["Interaction Overview Diagram"]
      Timing["Timing Diagram"]

1. Use Case Diagrams: Modeling User Interactions

Definition: Shows actors (users or external systems) and their interactions with the system via use cases.

Key Elements:

  • Actor: External entity (e.g., Customer, Admin).
  • Use Case: A function (e.g., "Place Order," "Cancel Booking").
  • Relationships:
    • <<includes>>: Mandatory sub-process (e.g., "Login" must precede "Order").
    • <<extends>>: Optional extension (e.g., "Apply Discount" if eligible).

Example: eSewa Payment System

sequenceDiagram
    actor User
    participant eSewa
    participant Bank
    User->>eSewa: Select Bill (NTC)
    eSewa->>User: Show Amount (Rs. 500)
    User->>eSewa: Confirm Payment
    eSewa->>Bank: Request Debit (User Account)
    Bank-->>eSewa: Approve/Reject
    eSewa->>User: Show Receipt

Real-World Tie: eSewa uses use case diagrams to model:

  • Customer → Pay Bill (NTC, Ncell).
  • Admin → Generate Reports.

Worked Example: Daraz Order Workflow

erDiagram
    Customer ||--o{ Order : "places"
    Order ||--|{ Product : "contains"
    Order ||--|| Payment : "has"
    Order ||--|{ Shipping : "triggers"
    Customer {
        string userID PK
        string name
        string email
        string phoneNumber
    }
    Order {
        int orderID PK
        date orderDate
        string status
        float totalAmount
    }
    Payment {
        int paymentID PK
        string method
        date paymentDate
    }
    Product {
        int productID PK
        string name
        float price
    }

Enhanced ER diagram with all key entities and attributes for Daraz order workflow Trace:

  1. Customer selects Product → Order is created.
  2. Order triggers Payment (Khalti/Nepal Bank).
  3. Shipping updates Order.status to "Delivered."

2. Class Diagrams: Blueprint of Objects

Definition: Represents classes, their attributes, methods, and relationships.

Syntax:

classDiagram
    class Customer {
        -userID: String
        -name: String
        +placeOrder(): void
        +cancelOrder(): void
    }
    class Order {
        -orderID: int
        -date: Date
        -status: String
    }
    Customer "1" --> "0..*" Order : places

Key Notations:

Symbol Meaning
- Private attribute/method
+ Public method
~ Protected
0..1 Zero or one (optional)
1..* One or more (mandatory)

Example: Ncell Billing System

classDiagram
    class Customer {
        -customerID: String
        -phoneNumber: String
        +calculateBill(): float
    }
    class Subscription {
        -planType: String
        -startDate: Date
    }
    Customer "1" -- "1" Subscription : has

Real-World Tie: Ncell uses class diagrams to model:

  • Customer ↔ Subscription (prepaid/postpaid plans).
  • Bill ↔ Payment (due dates, penalties).

3. Sequence Diagrams: Message Flows

Definition: Shows object interactions in time order (e.g., WhatsApp message delivery).

Example: WhatsApp Message Delivery

sequenceDiagram
    actor UserA
    participant WhatsAppServer
    participant UserB
    UserA->>WhatsAppServer: Send Message("Hi!")
    WhatsAppServer->>UserB: Deliver Message
    UserB->>WhatsAppServer: Read Receipt
    WhatsAppServer-->>UserA: Show "Seen"

Key Elements:

  • Lifelines: Vertical lines for objects.
  • Messages: Arrows with labels (e.g., Send, Reply).
  • Activation Bars: Show when an object is active.

Worked Example: Kathmandu Traffic Route Optimization

DataProcessOptimizeFeedbackTraffic SensorCentral ServerAI EngineSignal Controller
Kathmandu Traffic Route Optimization System Architecture

Trace:

  1. Sensor detects congestion → sends data to Server.
  2. Server runs optimization → updates Signal timings.

4. Activity Diagrams: Workflow Modeling

Definition: Models process flows (e.g., Khalti’s payment approval).

Example: Khalti Payment Approval

stateDiagram-v2
    [*] --> Start
    Start --> CheckBalance: Verify Funds
    CheckBalance --> Approve: Sufficient?
    Approve --> DeductAmount: Yes
    DeductAmount --> UpdateStatus: Success
    UpdateStatus --> [*]
    Approve --> Reject: No
    Reject --> NotifyUser: Insufficient
    NotifyUser --> [*]

Real-World Tie: Khalti uses activity diagrams for:

  • Payment → Approval → Confirmation.
  • Refund → Dispute → Resolution.

5. State Machine Diagrams: Object Lifecycle

Definition: Shows state transitions of an object (e.g., Daraz order status).

Example: Daraz Order Status

stateDiagram-v2
    [*] --> Placed
    Placed --> Processing: Payment Confirmed
    Processing --> Shipped: Packed
    Shipped --> Delivered: Courier Update
    Delivered --> [*]
    Processing --> Cancelled: User Request

Key Elements:

  • States: Placed, Shipped, Delivered.
  • Transitions: Triggered by events (e.g., Payment Confirmed).

6. Deployment Diagrams: Hardware-Software Mapping

Definition: Shows physical deployment of software components.

Example: Nepal Stock Exchange (NEPSE) System

Real-World Tie: NEPSE deploys:

  • Web Server (public-facing).
  • App Server (business logic).
  • Database (SQL/NoSQL).

Comparison Table: Key UML Diagrams

Diagram Type Purpose Example Use Case
Use Case User interactions eSewa: Pay Bill
Class Object structure Ncell: Customer ↔ Plan
Sequence Message flows WhatsApp: Send Message
Activity Workflow processes Khalti: Payment Approval
State Machine Object lifecycle Daraz: Order Status
Deployment Hardware mapping NEPSE: Server Rack

In the Real World

  1. eSewa:

    • Uses use case diagrams to model Customer → Pay Bill (NTC, Ncell).
    • Sequence diagrams for Payment → Bank → Confirmation.
  2. Daraz:

    • Class diagrams define Order → Product → Shipping.
    • State diagrams track Order Status (Placed → Shipped → Delivered).
  3. Ncell:

    • Activity diagrams model Bill Generation → Payment → Due Date.
    • Deployment diagrams show Central Server ↔ Tower connections.
  4. Khalti:

    • Sequence diagrams for User → Khalti → Bank → Approval.
    • State machines for Transaction Status (Pending → Completed → Failed).
  5. Nepal Stock Exchange (NEPSE):

    • Class diagrams for Trader ↔ Stock ↔ Order.
    • Deployment diagrams for Exchange Server ↔ Broker Terminals.

Common Mistakes to Avoid

  1. Missing Multiplicity: Forgetting 1..* or 0..1 in class diagrams.

    • ❌ Customer → Order (no cardinality).
    • ✅ Customer "1" → "0..*" Order.
  2. Incorrect Relationships:

    • ❌ Using <<extends>> for mandatory steps (use <<includes>>).
    • ✅ Login <<includes>> Place Order.
  3. Overcomplicating Diagrams:

    • Avoid 20+ classes in one diagram. Split into modules (e.g., User Module, Payment Module).
  4. Ignoring Actors:

    • Always label external entities (e.g., Bank, Courier).

Exam Tip: How to Score Full Marks

  1. Label Everything:

    • Use <<stereotypes>> (<<extends>>, <<realizes>>).
    • Include multiplicity (1..*, 0..1).
  2. Show Real-World Tie:

    • Example: For a sequence diagram, mention "This is how WhatsApp delivers messages."
  3. Use Standard Notation:

    • Underline class names, italicize attributes/methods.
    • Use + for public, - for private.
  4. Practice Traces:

    • For activity diagrams, trace a path (e.g., "Happy Path" vs. "Error Path").
  5. Diagram Quality:

    • Neat, readable, and color-coded (e.g., actors in red, use cases in blue).

Based on the TU BITM syllabus for Software Design and Development (IT242), unit 4.

Discussion

Loading…