UML Diagram Types
UML provides 14 diagram types organized into structural and behavioral categories.
UML 2.x Diagram Taxonomy
UML Diagrams
├── Structural Diagrams (Static View)
│ ├── Class Diagram ★ Most used in LLD
│ ├── Object Diagram (instances at a point in time)
│ ├── Component Diagram (software components)
│ ├── Composite Structure (internal structure)
│ ├── Package Diagram (package organization)
│ └── Deployment Diagram (hardware deployment)
│
└── Behavioral Diagrams (Dynamic View)
├── Use Case Diagram (system functionality)
├── Activity Diagram (workflow/process)
├── State Machine Diagram (state transitions)
├── Sequence Diagram ★ Most used in LLD
│ ├── Communication Diagram (message routing)
├── Interaction Overview (interaction flows)
└── Timing Diagram (time constraints)
Diagram Selection Guide
| Need | Diagram | When |
|---|---|---|
| Design classes | Class Diagram | LLD phase |
| Show interactions | Sequence Diagram | Workflow design |
| Show states | State Machine | Complex object states |
| Show workflow | Activity Diagram | Business processes |
| Show components | Component Diagram | System architecture |
| Show deployment | Deployment Diagram | Infrastructure |
Structural Diagrams
Class Diagram: Shows classes, attributes, methods, relationships
Object Diagram: Shows instances at a specific moment
Component Diagram: Shows software components and dependencies
Deployment Diagram: Shows hardware and software deployment
Package Diagram: Shows package organization and dependencies
Behavioral Diagrams
Sequence Diagram: Shows message flow between objects over time
Activity Diagram: Shows workflow from start to end
State Machine Diagram: Shows state transitions of an object
Use Case Diagram: Shows system functionality from user perspective
LLD Focus
For Low-Level Design, focus on:
- Class Diagram: The primary LLD artifact
- Sequence Diagram: Show key interactions
- State Machine: For complex stateful objects
- Activity: For complex workflows
Class Notation
Class diagrams are the foundation of UML in LLD. Mastering class notation is essential.
Class Box
┌────────────────────────────┐
│ «stereotype» │
│ ClassName │
├────────────────────────────┤
│ - privateField: Type │
│ # protectedField: Type │
│ ~ packageField: Type │
│ + publicField: Type │
│ «static» - staticField: T │
├────────────────────────────┤
│ + publicMethod(): Return │
│ - privateMethod(): void │
│ # protectedMethod(): T │
│ ~ packageMethod(): void │
│ «abstract» + abstract(): T│
└────────────────────────────┘
Visibility Symbols
| Symbol | Visibility | Access |
|---|---|---|
+ |
Public | Everywhere |
- |
Private | Same class only |
# |
Protected | Same class + subclasses |
~ |
Package | Same package |
Stereotypes
«interface» → Interface class
«abstract» → Abstract class
«enumeration» → Enum type
«entity» → Domain entity
«valueObject» → Immutable value
«service» → Service class
«repository» → Data access class
«controller» → Controller class
Attributes Notation
- name: String // Simple attribute
- age: int = 0 // With default value
+ «static» count: int // Static attribute
- «final» id: String // Immutable attribute
- items: List<OrderItem> // Collection
+ «read-only» total: Money // Read-only
Methods Notation
+ getName(): String // Simple method
+ setAge(age: int): void // With parameters
+ «static» create(): User // Static method
+ «abstract» validate(): boolean // Abstract method
+ «final» process(): void // Cannot override
+ findByName(name: str): List<User> // Returns collection
Notes and Comments
┌──────────────────┐
│ User │ ╔═══════════════════╗
├──────────────────┤ ║ This class handles ║
│ - name: String │────▶║ user authentication║
└──────────────────┘ ╚═══════════════════╝
(UML note/comment)
Relationship Notation
UML defines several types of relationships between classes. Each has distinct semantics.
Relationship Types
┌─────────────────────────────────────────────────────────┐
│ UML Relationships │
├─────────────────────────────────────────────────────────┤
│ │
│ Association A ──────── B Structural relationship │
│ (Association) │
│ │
│ Aggregation A ◇──────── B Weak ownership (HAS-A) │
│ (Aggregation) Part can exist without whole │
│ │
│ Composition A ◆──────── B Strong ownership (HAS-A) │
│ (Composition) Part cannot exist without whole │
│ │
│ Inheritance A ─────▷ B IS-A relationship (extends)│
│ (Generalization) │
│ │
│ Implementation A - - -▷ B Implements interface │
│ (Realization) │
│ │
│ Dependency A - - -▶ B Uses B (method parameter) │
│ (Dependency) │
│ │
└─────────────────────────────────────────────────────────┘
Multiplicity
┌──────────┐ 1 0..* ┌──────────┐
│ Parent │──────────────▶│ Child │
└──────────┘ └──────────┘
Multiplicity Values:
1 Exactly one
0..1 Zero or one
* Zero or more (same as 0..*)
0..* Zero or more
1..* One or more
5 Exactly five
5..10 Between 5 and 10
Relationship Examples
Association:
┌──────────┐ 1 1 ┌──────────┐
│ User │──────────│ Address │
└──────────┘ └──────────┘
(User has one Address)
Aggregation:
┌──────────┐ 1 * ┌──────────┐
│ Team │◇────────│ Player │
└──────────┘ └──────────┘
(Team has Players, Players exist without Team)
Composition:
┌──────────┐ 1 * ┌──────────┐
│ House │◆────────│ Room │
└──────────┘ └──────────┘
(House has Rooms, Rooms don't exist without House)
Inheritance:
┌──────────┐
│ Shape │
└────┬─────┘
│ △
┌────┴──────┐ ┌──────────────┐
│ Circle │ │ Rectangle │
└───────────┘ └──────────────┘
(Circle IS-A Shape)
Implementation:
┌──────────────┐
│ «interface» │
│ Payable │
└──────┬───────┘
│ - -▷
┌──────┴───────┐
│ Invoice │
└──────────────┘
(Invoice implements Payable)
When to Use Each
| Relationship | Use When |
|---|---|
| Association | Objects reference each other |
| Aggregation | Whole owns parts, parts can exist independently |
| Composition | Whole owns parts, parts lifecycle tied to whole |
| Inheritance | Clear IS-A relationship |
| Implementation | Class fulfills interface contract |
| Dependency | Class uses another temporarily (method parameter) |
Practice Problems
Design a scalable UML Basics system. Cover high-level architecture, data model, and API design.
Solution
// Complete system design:
// - Functional + Non-functional requirements
// - Capacity estimation
// - Data model (SQL/NoSQL choice)
// - API endpoints
// - Component architecture
// - Scaling strategy
// - Monitoring & reliabilityHow would you scale UML Basics to handle 10x the current load? Identify bottlenecks and solutions.
Solution
// Scaling approach:
// 1. Load balancing
// 2. Database sharding/replication
// 3. Cache layer (Redis)
// 4. CDN for static assets
// 5. Async processing (queues)
// 6. Microservices decompositionAnalyze potential failure modes for UML Basics and design mitigation strategies.
Solution
// Failure mitigation:
// 1. Redundancy (multi-AZ)
// 2. Circuit breakers
// 3. Retry with backoff
// 4. Dead letter queues
// 5. Health checks
// 6. Graceful degradationQuiz
1. Which two UML diagram types are most used in LLD?
2. What does the diamond symbol (◆) represent in UML?
3. What does multiplicity 1..* mean?
4. What is the «interface» stereotype used for?
5. What does a dashed arrow (- - -▷) represent?
Flashcards
Question
What are the two main categories of UML diagrams?
Click to reveal answer
Answer
Structural (Class, Object, Component, Deployment, Package) and Behavioral (Sequence, Activity, State Machine, Use Case).
Question
What are the UML visibility symbols?
Click to reveal answer
Answer
+ Public, - Private, # Protected, ~ Package. These control access to class members.
Question
What is the difference between aggregation and composition?
Click to reveal answer
Answer
Aggregation (◇): weak ownership, part can exist independently. Composition (◆): strong ownership, part lifecycle tied to whole.
Question
What does the «interface» stereotype mean?
Click to reveal answer
Answer
Indicates the class box represents an interface, not a concrete class. Shows the contract that implementing classes must follow.
Question
When to use Class vs Sequence diagram?
Click to reveal answer
Answer
Class: static structure (classes, attributes, relationships). Sequence: dynamic behavior (message flow between objects over time).
Revision Notes
Key Takeaways
- 1.UML has 14 diagram types: structural and behavioral
- 2.Class and Sequence diagrams are the most used in LLD
- 3.UML symbols: + public, - private, # protected, ~ package
- 4.Relationships: association, aggregation, composition, inheritance, implementation
- 5.Multiplicity defines how many instances participate in a relationship
Interview Tips
- •Use class diagrams to show your design's static structure
- •Use sequence diagrams to show key workflows
- •Explain relationship types when discussing class connections
- •Choose the right diagram for the right purpose
Cheat Sheet
UML Basics - Cheat Sheet
Diagram Categories:
Structural: Class, Object, Component, Deployment, Package
Behavioral: Sequence, Activity, State Machine, Use Case
LLD Focus:
- Class Diagram (primary)
- Sequence Diagram (interactions)
- State Machine (complex states)
Visibility:
- Public, - Private, # Protected, ~ Package
Relationships:
| Symbol | Name | Meaning |
|---|---|---|
| ──── | Association | Structural ref |
| ◇──── | Aggregation | Weak HAS-A |
| ◆──── | Composition | Strong HAS-A |
| ────▷ | Inheritance | IS-A |
| - - -▷ | Implementation | Interface |
Multiplicity:
1, 0..1, , 0.., 1..*, 5