Question

I am working on the parking lot example, and made few assumptions as I design.

I have couple of questions in assigning attributes to Items/Objects.

1) If parkingSpace is not assigned by a system, i.e., user just into Lot, finds an appropriate place (car/bike/truck/handicapped) and parks his car.

I think I don't need a ParkingSpace object, but instead, I can keep a count of no_of_free_places for each of the category_of_parking_space.

Since parking space is big, we just maintain three variables.

  • no_of_free_slots_Car
  • no_of_free_slots_Bike
  • no_free_slots_Truck
  • no_free_slots_Handicapped

when a vehicle comes in, we just decrease one of the above values (which means, of the available X places, user chooses one and parks there), & when vehicles goes out, we increase the corresponding value. (in short, parking lot is not assigned by anyone, vehicle just goes to one of the eligible places & parks there)

2) Assuming we have a single global parking meter.
--> Should the start_time/end_time be an attribute of Vehicle?
Or
--> vehicle_id, start_time, end_time be part of ParkingMeter.

3) Assuming the need for parkingSpace object, should 4_wheeler, 2_wheeler, handicapped be a enum type, or a separate class altogether.
If its enum, we can use findEmptySlot(parkingSpace_type);
If they are separate class altogether, and ParkingLot has a method findEmptySlot();
How can we get the appropriate Slot?

ParkingMeter will be responsible to setting the vehicle's start, end times right?

If the has multiple amounts, 1hr - 20$, 2hr - 30$, 3hr - 40$, 5hr - 50$
is it good have these part of ParkingMeter class or, include them in a separate class "ParkingPrice"

Was it helpful?

Solution

Okay,

  1. I didn't really understand the question, but I would indeed use an array ParkingSpace objects to describe the spaces in the park.
  2. Since the time is per vehicle, the time should be set on the vehicle.
  3. I'd use a different class for each, and each should be extending the abstract class Vehicle. It allows for flexibility with common and unique attributes of each vehicle type (serial number for all vehicles, but only 4_wheelers have doors for instance). As for how to find empty parking spaces, each ParkingSpace object would have a $takenBy property, which would hold an instance of the vehicle object occupies it. It should default to null, then, you simply iterate through the array of spaces in your ParkingLot class, and find the one with $space->takenBy == null.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top