Requirements

  1. The ride sharing service should allow passengers to request rides and drivers to accept and fulfill those ride requests.
  2. Passengers should be able to specify their pickup location, destination, and desired ride type (e.g., regular, premium).
  3. Drivers should be able to see available ride requests and choose to accept or decline them.
  4. The system should match ride requests with available drivers based on proximity and other factors.
  5. The system should calculate the fare for each ride based on distance, time, and ride type.
  6. The system should handle payments and process transactions between passengers and drivers.
  7. The system should provide real-time tracking of ongoing rides and notify passengers and drivers about ride status updates.
  8. The system should handle concurrent requests and ensure data consistency.

Entities Idea: Give each class the responsibility over its own state. Ride: manages it’s own lifecycle, assigns driver, starts ride, completes ride Passenger: must initiate demand, requests ride with pickup and drop-off locations Driver: must control availability, is_available(), updates its location

Class Design

Passenger:
id: uuid

request_ride(pickup_location, dropoff_location, ride_type)
Location:
latitude: float
longitude: float
Driver:
id: uuid
vehicle_type: VehicleType
status: DriverStatus
current_location: Location

is_available() -> bool
update_location(location)
DriverStatus:
AVAILABLE, ON_RIDE, OFFLINE
Ride:
id: uuid
type: RideType
status: RideStatus
pickup_loc: Location
dropoff_loc: Location
fare: float
passenger_id: uuid
driver_id: uuid | None

assign_driver(driver_id)
start()
complete()
RideStatus:
REQUESTED, ASSIGNED, ONGOING, COMPLETED
RideType:
AUTO, CAB, PREMIUM
VehicleType:
AUTO, CAB, PREMIUM
RideSharingService:
fare_strategy: FareStrategy

get_fare(pickup_location, dropoff_location, ride_type) -> float
request_ride(user_id, pickup_loc, dropoff_loc, ride_type) -> uuid
assign_driver(driver_id, ride_id) -> bool
start_ride(driver_id, ride_id)
complete_ride(driver_id, ride_id)
FareStrategy:
calculate(pickup_location, dropoff_location, ride_type) -> float