Requirements


Functional Requirements:


  • Manage vehicle parking across multiple floors.
  • Parking spot assignment based on vehicle size.
  • Spot availability checking.
    • If spots available, assign a random spot.
    • If spots full, tell user there are no spots available and to join a waitlist.
    • Create waitlist queue.
  • Create Ticket creation and ticket processing service.
  • Fee calculation based on parking duration. Fee's are calculated as follows:
    • 0-1 hour: $1
    • 2-3 hours: $3
    • 3-5 hours: $6
    • 5-9 hours: $9
    • 9+ hours: $24 (assume full 24 hours)


Non-Functional Requirements:

  • Handle ticket assignment race conditions - ie: 2 drivers both want spot A, both can't be assigned the same spot. Solution: 1 synchronized method for inserting driver spot permission and 1 synchronized method for deleting driver spot permission. Use a Concurrent Hashmap to handle fast reads and updates from users.
  • Handle extensibility for operations like payment methods through the adapter design pattern.


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...


Here's a Class Diagram illustrating the relationships of the core objects and too each other:


classDiagram

 class ParkingGarage {

  +ConcurrentHashMap<int, ParkingFloor> floors

  +TicketService ticketService

  +CreateTicket() Ticket

  +CloseTicket() Ticket

 }

 class TicketService {

  -List<Tickets> tickets

  -Queue<Vehicle> waitList

  +CreateTicket(floors) int

  +CloseTicket(ticketId) int

  +alertSpotOpen() void


 }

 class Vehicle {

  +getMake/Model/Year() String/Int

  +setMake/Model/year() void

  +String make

  +String model

  +int year

  +Driver user

  +String liscensePlateNum

 }

 class ParkingFloor {

  +getAvailableSpots() availableSpots

  +updateParkingSpot(parkingSpot) bool

  +int floorNum

  +ParkingSpots[] spots

  +Queue<ParkingSpots> availableSpots

 }

 class ParkingSpot {

  -method() void

  -String[] vehicleTypesAllowed

  -int spotNum

  -Vehicle Vehicle

  -Boolean assigned

 }

 class Driver {

  +method() void

  +String fn

  +String ln

  +int age

  +String email

 }

 class Ticket {

  +Date check_in

  +Date check_out

  +Boolean status

  +Int fee

  +ParkingSpot spot

  +feeCalculation() Float

 }


 ParkingGarage *-- TicketService

 TicketService "1" --> "*" Ticket

 TicketService "1" --> "0..*" Vehicle

 Vehicle "1" --> "1" Driver

 ParkingGarage "1" --> "0..*" ParkingFloor

 ParkingFloor "1" --> "0..*" ParkingSpot

 ParkingSpot "1" --> "0..1" Vehicle




APIs & Class Members

For each class, define the attributes (data) it will hold and the methods (functions) that operate on the attributes. Ensure they align with the object's responsibilities and adhere to the principle of encapsulation. Write your code in the code editor below.





Deep Dive

Explain design tradeoffs you considered. Check and explain whether your design adheres to SOLID principles. Explain how your design can handle changes in scale and whether it would be easy to extend with new functionalities. Identify areas for future improvement...


Future improvement:

  • Implement an adapter pattern for handling different forms of payment.
  • Flesh out the payment strategy more concretely.
  • Consider implementing an observer pattern for the waitlist for the ticketService using Drivers as a subscriber.
  • Create ENUM for Vehicle type to avoid spelling errors and more clear organization.