So I understand that the ParkingLot contains data structures for all the terminals (entrances and exits) and tickets and parking spots and and it has the getInstance() function to access the singleton instance of ParkingLot. So once the ParkingLot instance is created, all of its entrances and terminals must contain a reference to this PakingLot instance so it can communicate to it? For example, when the getTicket() function or validateTicket() function is called, how does the Entrance or Exit instances update the list of tickets that’s maintained in the ParkingLot?
Yes, you are right. Once the ParkingLot instance is created, all of its entrances and exits should contain a reference to this ParkingLot instance so they can communicate with it.
getTicket() function is called at an entrance terminal, the Entrance instance will create a new Ticket object and add it to the list of tickets maintained in the ParkingLot instance. This is typically done by calling a method on the ParkingLot instance, such as
addTicket(ticket). Similarly, when the
validateTicket() function is called at an exit terminal, the Exit instance will need to check the list of tickets maintained in the ParkingLot instance to see if the ticket is valid. This can be done by calling a method on the ParkingLot instance, such as
getTicketById(ticketId), which returns the Ticket object with the specified ID.
Thank you for your quick response! This makes sense now. Just wanted to add that being able to ask questions here has been very helpful in going through the course. Thank you.