Requirements


Functional requirements:

  1. The parking lot charges vehicle an hourly rate. There is no grace period. The fee is paid by the vehicle driver on exit.
  2. The parking lot tracks availability of parking spot and enforces size constraints. Each parking spot is on a parking floor and there can be multiple parking floors.
  3. The parking lot is integrated with an external system for payment processing.


Non-functional requirements:

  1. The parking lot should be available 24/7. It should handle dependency failure in external payment system without stopping vehicle to exit.
  2. Payments should be logged for audit purpose.


Define Core Objects


```rust

struct ParkingLotController {

// pub for operator to inspect status

pub parking_lot: ParkingLot,

payment_processor: PaymentProcessor

}


impl ParkingLotController {

// return floor and spot id

fn enter(vehicle: Vehicle) -> (u32, u32);


// release parking spot and charge payment

fn exit(vehicle: Vehicle, info: PaymentInfo) -> Result;


// operator methods below:

// clear a parking spot (if system is inconsistent)

fn clear_spot(u32: floor, u32: spot) -> bool;

// fix payment system

fn update_payment_processor(...) -> ...

}


struct ParkingLot {

id: u32,

floors: Vec,

}


impl ParkingSpot {

fn acquire(id: u32, vehicle: Vehicle) -> bool;

fn release(id: u32) -> bool;

}


struct PaymentProcessor {

fn charge(amount: f32, info: PaymentInfo) -> Result;

}


struct ParkingFloor {

id: usize,

spots: Vec,

}


struct ParkingSpot {

id: usize,

size: VehicleSize,

occupied: Option,

}


enum VehicleSize {

compact, normal, large

}


struct Vehicle {

license_plate: String,

size: VehicleSize,

}



```




Analyze Relationships

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






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...






Design Patterns

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






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 Car { ... } // Example





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...