UML Diagrams
UML Class Diagrams
Visual representation of classes, their attributes, methods, and relationships. Essential for LLD interviews.
15 min readEssential for Interviews
1Class Notation
A class is represented as a rectangle divided into three sections: class name (top), attributes (middle), and methods (bottom).
Class Box Structure
+
Public
Accessible anywhere
-
Private
Class only
#
Protected
Class + subclasses
~
Package
Same package
2Relationship Notation
UML Relationship Symbols
Memory Aid for Diamonds
- Filled Diamond (Composition): "Filled = Full ownership" - part dies with whole
- Empty Diamond (Aggregation): "Empty = External" - part can exist independently
3Multiplicity
| Notation | Meaning | Example |
|---|---|---|
| 1 | Exactly one | Order has 1 Customer |
| 0..1 | Zero or one (optional) | Person has 0..1 Spouse |
| * | Zero or more | Customer has * Orders |
| 1..* | One or more | Order has 1..* Items |
| n..m | Specific range | Car has 3..4 Wheels |
4Complete Example: E-Commerce
E-Commerce Class Diagram
Customer places Orders (1 to many). Orders contain OrderItems (composition). OrderItems reference Products.
5Interview Follow-up Questions
Interview Follow-up Questions
Common follow-up questions interviewers ask
6Key Takeaways
1Class box has three sections: name, attributes, methods.
2Visibility: + public, - private, # protected.
3Filled diamond = Composition (strong), Empty diamond = Aggregation (weak).
4Hollow triangle = Inheritance/Realization, Arrow = Association/Dependency.
5Multiplicity shows how many: 1, *, 1..*, 0..1.
6Practice drawing diagrams for common problems (Parking Lot, etc.).