#ifndef _PARKING_LOT_H_
#define _PARKING_LOT_H_
#include <memory>
#include <vector>
#include <unordered_map>
#include <iostream>
class Slot
{
public:
Slot(longint);
virtual ~Slot();
void AssignCar(const std::string& carNum);
longint GetId() const;
void ReleaseSlot();
private:
longint id;
std::string carNum;
};
class ParkingLot
{
public:
static ParkingLot& GetParkingLot();
longint DriveIn(const std::string& carNum); //finds free slot for parking, marks slot as occupied, returns the occupied slot no.
void DriveOut(const std::string& carNum); //frees the slot, deletes car details from the slot.
void ShowAllParked() const; //shows all the cars currently present in the parking.
longint LocateCar(const std::string& carNum); //gives slot number of a car given the car's reg. number.
std::string GetSlotInfo(longint slotId); //gives slot info like car parked in the slot, location etc.
virtual ~ParkingLot();
private:
ParkingLot();
ParkingLot(const ParkingLot&) = delete;
ParkingLot(ParkingLot&&) = delete;
ParkingLot& operator=(const ParkingLot&) = delete;
ParkingLot& operator=(ParkingLot&&) = delete;
static std::vector<std::unique_ptr<Slot>> freeSlots; //list of free slots
static std::vector<std::unique_ptr<Slot>> filledSlots; //list of occupied slots
static std::unordered_map<std::string, longint> carMap; //map for car number to slot number relation
static std::unordered_map<longint, std::string> slotMap; //map for slot number to car number relation
staticconstlongint MAX_SLOTS; //maximum capacity of parking lot
staticbool isInitialised;
staticlongint totalCars;
};
#endif
1. A class that has only static variables isn't a real class. So for now forget about 'static'.
2. Provide ParkingLot a public constructor with the capacity. You can have multiple parking lots with different capacities.
3. At the first sight having a map for quickly finding information seems to be a good idea. But having multiple variables for the same information raises the maintaining effort and is actually error prone. So remove the maps and find the information you need in the vector itself.
4. totalCars seems to be unnecessary. What are you trying to achieve with it? Rather remove it.
1) A class that has only static variables isn't a real class. So for now forget about 'static'.
==> 1') Tnx :) That means we can use non static member variables for a singleton class ?
Is it that static variables should be avoided as far as possible, if yes, why ?
Thanks :)
PS : Is this not the right forum to ask C++ design related questions as I see very less responses to design related questions.
Kindly let me know if there are any better forums for the same.