UML & ModelingClass DiagramsMedium⏱️ ~2 min

Class Diagram Structure and Notation

Class diagrams use standardized UML notation to represent classes and their members. Understanding this notation is essential for LLD interviews where you must communicate designs precisely.

ParkingSpot
- spotId: String
- spotType: SpotType
- isOccupied: Boolean
# assignedVehicle: Vehicle
+ assignVehicle(vehicle): Boolean
+ releaseVehicle(): void
+ isAvailable(): Boolean
- validateVehicleSize(): Boolean
Visibility Modifiers:
  • + Public: Accessible from any class (API methods like assignVehicle())
  • - Private: Accessible only within the class (internal state like spotId)
  • # Protected: Accessible within the class and subclasses (shared data like assignedVehicle)
  • ~ Package: Accessible within the same package (less common in interviews)
Method Signature Format:
visibility methodName(param1: Type1, param2: Type2): ReturnType
Examples:
  • + calculateFee(duration: Integer): Money
  • - validateParkingRules(vehicle: Vehicle, spot: ParkingSpot): Boolean
  • # notifyObservers(event: ParkingEvent): void
Abstract Classes and Interfaces:
Vehicle
- vehicleId: String
- licenseNumber: String
+ park(spot): Boolean
+ getVehicleType(): Type
«interface»
PaymentStrategy
+ processPayment(amount): Receipt
Note: Abstract class names and abstract methods are shown in italics. Interfaces use dashed borders with «interface» stereotype.
Interview Tip: When drawing on a whiteboard, you can skip attribute types and method parameters for brevity. But if the interviewer asks "What's the signature of calculateFee()?", be ready to provide the complete signature with types.
💡 Key Takeaways
Classes have three compartments: name (top), attributes (middle), methods (bottom)
Visibility modifiers: + public, - private, # protected, ~ package
Method signatures follow format: visibility name(params): ReturnType
Abstract classes use italic text for class name and abstract methods
Interfaces use dashed borders with «interface» stereotype above the name
Static members are underlined in UML notation
📌 Examples
1ParkingSpot class with private spotId, protected assignedVehicle, and public assignVehicle() method
2Abstract Vehicle class with concrete attributes and abstract getVehicleType() method
3PaymentStrategy interface with processPayment() method implemented by CreditCardPayment and CashPayment
← Back to Class Diagrams Overview
Class Diagram Structure and Notation | Class Diagrams - System Overflow