Software EngineeringUnit 1310 min read
UML Modeling: Diagrams, Patterns & Real-World Systems
Unit 13 of Software Engineering covers Unified Modeling Language (UML) fundamentals—structural (class, component, deployment) and behavioral (use case, sequence, state) diagrams—plus model-driven architecture (MDA), transformations, and how these tools solve real problems in Nepalese tech (eSewa, Ncell, Daraz). Include
What is UML and Why Model Software?
Software modeling uses Unified Modeling Language (UML) to visualize systems before coding. UML is a standardized language (not a programming language) with 14 diagram types grouped into structural (showing static relationships) and behavioral (showing dynamic interactions).
Why Model?
- Clarity: Avoids ambiguity in requirements (e.g., eSewa’s payment flow).
- Reusability: Standard diagrams (like class diagrams) work across projects.
- Validation: Catches design flaws early (e.g., Ncell’s billing system errors).
- Communication: Non-technical stakeholders (e.g., Daraz managers) understand visuals.
Structural Diagrams: The "Blueprints" of Software
These show static relationships between components. Key diagrams:
1. Class Diagram
Definition: Shows classes (objects), their attributes, methods, and relationships (association, inheritance, aggregation, composition).
Example: A bank account system with Customer, Account, and Transaction classes.
classDiagram
class Customer {
-id: int
-name: string
+openAccount()
}
class Account {
-accountNumber: string
-balance: float
+deposit(amount)
+withdraw(amount)
}
class Transaction {
-transactionId: int
-amount: float
+record()
}
Customer "1" -- "0..*" Account : opens
Account "1" -- "1..*" Transaction : containsReal-World Tie:
- eSewa’s class diagram would include
User,PaymentGateway, andServiceProviderclasses, withUseraggregatingPaymentHistory. - Worked Example: Model a Daraz order system with classes
Customer,Order,Product, andDelivery. Use composition forOrdercontainingOrderItem.
Key Relationships:
| Relationship | Symbol | Meaning | Example |
|---|---|---|---|
| Association | Solid line | General link | Customer places Order |
| Inheritance | Hollow triangle | "Is-a" (e.g., SavingsAccount is an Account) |
|
| Aggregation | Diamond (white) | "Has-a" (weak, shared lifetime) | Car has Engine |
| Composition | Diamond (black) | "Owns" (strong, lifetime tied) | House contains Room |
2. Component Diagram
Definition: Shows high-level modules (e.g., libraries, services) and their dependencies. Example: A WhatsApp message system with components:
UserInterface(UI)MessageService(handles sending/receiving)Database(stores chats)
Real-World Tie:
- Khalti’s payment system uses components like
UserAuth,PaymentGateway, andNotificationService. - Worked Example: Model NTC’s billing system with components
CustomerPortal,BillingEngine, andPaymentProcessor.
3. Deployment Diagram
Definition: Shows hardware nodes (servers, devices) and software deployment. Example: Ncell’s network with:
- Nodes: Base stations, central server, user phones.
- Artifacts:
BillingSoftware,CustomerApp.
Behavioral Diagrams: How Software "Moves"
These show dynamic interactions (e.g., user actions, system responses).
1. Use Case Diagram
Definition: Shows actors (users/other systems) and use cases (actions). Example: Pathao ride system:
- Actors:
Customer,Driver,Admin. - Use Cases:
Book Ride,Track Ride,Cancel Ride.
Real-World Tie:
- eSewa’s use case diagram includes actors
User,Government,Bankand use cases likePay Bill,Check Balance. - Worked Example: Model NEPSE’s trading system with actors
Broker,Investor,Adminand use casesPlace Order,View Portfolio.
2. Sequence Diagram
Definition: Shows object interactions in time order (messages passed between objects). Example: WhatsApp message flow:
UsersendsMessage.MessageServiceprocesses it.Databasestores it.NotificationServicealerts recipient.
sequenceDiagram
participant User
participant MessageService
participant Database
participant NotificationService
User->>MessageService: sendMessage("Hi!")
MessageService->>Database: store(message)
MessageService->>NotificationService: alertRecipient()
NotificationService->>User2: showNotification()Real-World Tie:
- Khalti’s payment sequence:
UserselectsPay.PaymentGatewayrequestsBank.Bankprocesses and confirms.KhaltiupdatesUserbalance.
- Worked Example: Trace a Daraz order from
Customer→OrderService→Inventory→Delivery.
3. State Diagram
Definition: Shows object state transitions (e.g., traffic light, order status). Example: Kathmandu traffic route system for a vehicle:
- States:
Waiting,Moving,Stopped. - Transitions:
greenLight→Moving,redLight→Stopped.
stateDiagram-v2
[*] --> Waiting
Waiting --> Moving : greenLight()
Moving --> Stopped : redLight()
Stopped --> Waiting : lightTurnsGreen()
Stopped --> [*]Real-World Tie:
- Ncell’s call state:
Idle→Ringing→Connected→Ended. - Worked Example: Model eSewa’s payment status:
Pending→Processing→Completed/Failed.
Model-Driven Architecture (MDA)
Definition: Separates platform-independent models (PIM) from platform-specific models (PSM) using transformations. Process:
- Create PIM (e.g., class diagram of a banking system).
- Apply transformation rules (e.g., "convert to Java").
- Generate PSM (Java code + database schema).
flowchart TD
A["PIM: Class Diagram"] -->|"Transformation"| B["PSM: Java + DB"]
B --> C["Deployed System"]Real-World Tie:
- Google’s Android apps use MDA: designers create UI mockups (PIM), tools generate code (PSM).
- Worked Example: Transform a WhatsApp chat PIM (classes
User,Message) into a Python PSM with SQLAlchemy models.
Exam Tip: How to Score Full Marks
- Diagrams > Text: Always draw neat mermaid diagrams (use the exact syntax shown above). Label every element.
- Real-World Links: Tie every example to Nepalese apps (eSewa, Khalti, Daraz). Examiners love this.
- Example: "Like eSewa’s payment flow, this sequence diagram shows..."
- Definitions + Examples: For each diagram type, give:
- Definition (1 line).
- Example (draw it).
- Real-World Use (name a Nepalese app).
- Avoid Common Mistakes:
- ❌ Drawing inheritance as a solid line (use hollow triangle).
- ❌ Forgetting to label arrows in sequence diagrams.
- ❌ Using UML for flowcharts (use activity diagrams instead).
- Short-Answer Secrets:
- Waterfall model: "Sequential phases (requirements → design → ... → maintenance). Use when requirements are stable (e.g., NTC’s billing system)."
- Event-driven modeling: "Systems react to events (e.g., WhatsApp’s
onMessageReceived)."
In the Real World
eSewa’s Payment Flow
- UML Used: Sequence diagram for
User→PaymentGateway→Bank→eSewa. - Why: Ensures every step (authentication, deduction, confirmation) is visualized before coding.
- UML Used: Sequence diagram for
Khalti’s Component Diagram
- UML Used: Component diagram with
UserAuth,TransactionService,Notification. - Why: Helps developers see dependencies (e.g.,
TransactionServiceneedsBankAPI).
- UML Used: Component diagram with
Daraz’s Order State Machine
- UML Used: State diagram for
Orderstates:Placed→Processing→Shipped→Delivered. - Why: Prevents lost orders by modeling transitions (e.g., "Cannot ship if
PaymentFailed").
- UML Used: State diagram for
Ncell’s Deployment Diagram
- UML Used: Shows base stations, central server, and
BillingSoftwareartifact. - Why: Ensures scalability (e.g., adding more base stations for Kathmandu traffic).
- UML Used: Shows base stations, central server, and
Pathao’s Use Case Diagram
- UML Used: Actors
Customer,Driver,Adminwith use cases likeBook Ride. - Why: Validates requirements (e.g., "Does the driver need to accept rides?").
- UML Used: Actors
Common Pitfalls and How to Avoid Them
| Mistake | Fix |
|---|---|
| Confusing aggregation/composition | Remember: White diamond = weak (aggregation), black = strong (composition). |
| Missing lifelines in sequence diagrams | Always label objects vertically (e.g., User, Server). |
| Drawing inheritance as a line | Use a hollow triangle for "is-a" relationships. |
| Overcomplicating diagrams | Start simple! Use 3–5 classes in examples. |
| Ignoring real-world context | Always relate to Nepalese apps (eSewa, Khalti, etc.). |
Practice Questions (Exam-Style)
- Draw a class diagram for a bank ATM system with classes
Customer,Account,ATM, andTransaction. Use inheritance forSavingsAccountandCurrentAccount. - Explain how MDA helps in developing WhatsApp’s backend. Include a transformation step.
- Model the state transitions of a Daraz order from
PlacedtoCancelled. What event triggersCancelled? - Compare structural and behavioral diagrams using a table. Give one Nepalese app example for each.
- Why would NTC use a deployment diagram? Draw a simple version with 3 nodes.
Final Note: UML is not just for exams—it’s how real engineers (at Google, Khalti, or Ncell) design systems. Master the diagrams, and you’ll stand out in interviews too!
Based on the TU BIT syllabus for Software Engineering (BIT302), unit 13.
Discussion
Loading…