2

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"

Nawaz
  • 353,942
  • 115
  • 666
  • 851
sravanreddy001
  • 257
  • 1
  • 5
  • 17

1 Answers1

3

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.
Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
  • I have edited the question adding more information for the first part. The 2nd and 3rd ones are fine. Please look into 1st part. – sravanreddy001 Feb 26 '12 at 16:41
  • 1
    So you're asking if you should make a Space class or just decrease variables. I say keep an array of spaces (or an array for each space type). It allows flexibility in terms of detecting which car is in which, and even a reference to the actual car holding the space (as per my 3rd answer). – Madara's Ghost Feb 26 '12 at 17:20
  • Thank you.. I have added additional post toward the end of original post, can u look into that? – sravanreddy001 Feb 26 '12 at 23:21
  • Question, is there a parking meter per parking space? or per lot? – Madara's Ghost Feb 27 '12 at 07:08
  • Assuming a global/single parking meter for a lot, assuming the installation cost. – sravanreddy001 Feb 27 '12 at 21:49
  • Have the ParkingMeter handle the time counting and calculation, and having it output the result for all other classes to use (for instance, the GateWay that allows cars to exit will ask the ParkingMeter for the total price a specific car needs to pay. – Madara's Ghost Feb 28 '12 at 07:57