Requirements

Determine the different ways the system will be used. This includes main functions the system needs to perform and who will use it.

  • Assign based on vehicle size
  • Check if spaces are available
  • Calculate fee based on time spent


Define Core Objects

Based on the requirements and use cases, identify the main objects of the system...

  • Vehicle
  • Parking Spot
  • Parking Lot



Analyze Relationships

Determine how these objects will interact with each other to fulfill the use cases...

  • Parking Lot has multiple Parking Spots
  • Vehicles occupy Parking Spots




Establish Hierarchy

Design inheritance trees where applicable to promote code reuse and polymorphism. This step involves identifying common attributes and behaviors that can be abstracted into parent classes...

  • None immediately




Design Patterns

Consider using design patterns (e.g., Factory, Singleton, Observer, Strategy) that fit the problem...

Singleton might be good for the ParkingLot class




Define Class Members (write code)

Attributes: For each class, define the attributes (data) it will hold...

Methods: Define the methods (functions) that operate on the attributes. Ensure they align with the object's responsibilities and adhere to the principle of encapsulation.


public class Vehicle { private int size; public Vehicle (int s) { this.size = s; } public int GetSize() { return size; } } public class ParkingLot { ParkingSpot[][] lot; private double parkingFee; public ParkingLot (int[][] sizes, int numFloors, int numSpots, pFee) { lot = new ParkingSpot[numFloors][numSpots]; for (int i = 0; i < sizes.length; i++) { for (int j = 0; j < sizes[i].length; j++) { lot[i][j] = new ParkingSpot(sizes[i][j], false); this.parkingFee = pFee; } public int CheckAvailability(int size) { for (int i = 0; i < lot.length; i++) { for (int j = 0; j < lot[i].length; j++) { if (lot[i][j].IsOccupied() && lot[i][j].GetMaxSize() >= size) { return lot[i][j].GetMaxSize(); } } } return -1; } } public class ParkingSpot { private int maxSize; private boolean occupied; public ParkingSpot (int mSize, boolean o) { this.maxSize = mSize; this.occupied = o; } public void SetOccupied(boolean set) { occupied = set; } public boolean IsOccupied() { return occupied; } public int GetMaxSize() { return maxSize; } }






Adhere to SOLID Guidelines

Check and explain whether your design adheres to solid principles (Ask interviewer what SOLID principle is if you can not recall it.)...






Consider Scalability and Flexibility

Explain how your design can handle changes in scale and whether it would be easily to extend with new functionalities...






Create/Explain your diagram(s)

Try creating a class, flow, state and/or sequence diagram using the diagramming tool. Mermaid flow diagrams can be used to represent system use cases. You can ask the interviewer bot to create a starter diagram if unfamiliar with the tool. Briefly explain your diagrams if necessary...






Future improvements

Critically examine your design for any flaws or areas for future improvement...