Class Diagram – Car Parking
A Class Diagram models the static structure of the system by representing classes, their attributes, methods, and relationships. It helps students understand object-oriented principles such as inheritance, composition, and associations in the context of the Car Parking domain.
1. Major Classes and Their Responsibilities
Below are the core classes identified in a typical Car Parking System:
A. ParkingLot
Attributes:
lotId: int
location: String
capacity: int
availableSlots: int
Methods:
getAvailableSlots(): int
updateSlotAvailability(): void
B. ParkingSlot
Attributes:
slotId: int
isOccupied: boolean
vehicleType: String
floorNumber: int
Methods:
assignVehicle(vehicle: Vehicle): void
vacateSlot(): void
C. Vehicle
Attributes:
vehicleNumber: String
ownerName: String
vehicleType: String
Methods:
getDetails(): String
D. Ticket
Attributes:
ticketId: int
entryTime: DateTime
exitTime: DateTime
slot: ParkingSlot
vehicle: Vehicle
Methods:
calculateDuration(): int
generateTicket(): void
E. Payment
Attributes:
paymentId: int
ticket: Ticket
amount: double
paymentMethod: String
paymentStatus: String
Methods:
processPayment(): boolean
generateReceipt(): String
F. User (Abstract Class)
Attributes:
userId: int
name: String
contactInfo: String
Methods:
login(): boolean
G. Driver (Extends User)
Attributes:
membershipId: String
Methods:
requestSlot(): Ticket
payForParking(): Payment
H. Admin (Extends User)
Methods:
configureRates(): void
generateReports(): List
monitorLotStatus(): void
I. Sensor
Attributes:
sensorId: int
type: String
(e.g., motion, barrier)status: boolean
Methods:
detectVehicle(): boolean
updateSystem(): void
2. Relationships Between Classes
- ParkingLot contains multiple ParkingSlots (Composition)
- ParkingSlot has one Vehicle (Aggregation)
- Vehicle is associated with one Ticket
- Ticket is linked to one Payment
- User is the base class for both Driver and Admin (Inheritance)
- Sensor interacts with ParkingSlot and ParkingLot
3. How to Explain This in Class
- Start by identifying real-world entities and map them to classes.
- Explain attributes as properties and methods as behaviors.
- Emphasize relationships like composition (ParkingLot → ParkingSlot) and inheritance (User → Driver/Admin).
- Demonstrate how new classes can be easily added without breaking existing design (Open/Closed Principle).
- Optionally, draw the UML diagram using boxes and arrows to visually reinforce the structure.