Core Objects & Relationships
Based on the requirements and use cases, identify the main objects of the system and analyze how they interact and relate to each other...
Following are the entity classes
- ParkingLot
- ParkingSpot
- Vehicle
- ParkingTicket
Following are the utility classes
- FeesCalculator
- GateUtility
- FeeStrategy
ParkingLot
- ParkingLot class contains a list of ParkingSpots and list of active parking tickets
- Responsibility - Contains the overall list of all parkingspots. Will be used by the utility classes to decide which spots are empty. This class by itself does not contain any intelligence. It's only used to store the list of all parking spot objects
- Each parking lot contains an id that is globally unique
ParkingFloor
- Uniquely identifies the floor in the parking lot
ParkingSpot
- ParkingSpot contains the info about the size of the parking spot , which parkingfloor, unique id of the parking spot ( local to that parking lot ). It also contains a flag that indicates whether it's occupied or not
- Responsibility - Contains all the details about the parking spot and its current state ( available or not). It does not possess any other intelligence
Vehicle
- It is an interface that can be implemented by any type of vehice - 2 wheeler, car , truck and so on. It contains a registration id
- Responsibility - This class contains information about how to identify the vehicle. the type of the object will indicate its size.It does not possess any other intelligence
ParkingTicket
- It contains the info about the car ( registration id ), parking spot id, entry time.
- The FeeCalculator utility will calculate based on the parking ticket's entry time and the fee strategy
- Once a parkingTicket is created, it will be added to the list of active tickets in ParkingSlot
Utility Classes
GateUtility
- This utility is used to allow or reject a car at the gate. It will lookup the ParkingLot list of spots to find out availability and decide
- This utility will also generate a parkingTicket and add it to the ParkingLot's list of tickets and also give it to the caller
FeeCalculator
- FeeCalculator will take a parkingTicket and calculate the fees based on the exit time and the fee strategy. Fee Strategy is an interface that is implemented by multiple classes for eg: SmallSpotFeeStrategy, LargeSpotFeeStrategy and so on. The corresponding strategy is loaded by FeeCalculator based on the ParkingSpot which can be retrieved from the parkingTicket