advancedCapstone: Ride-Sharing App

Why is a dedicated matching service that coordinates drivers and passengers described as a Mediator, and what would be lost if Driver and Passenger referenced each other directly instead?

A Mediator is a dedicated coordinating object that sits between two or more kinds of collaborators so that none of them need direct references to each other -- all communication and coordination routes through the mediator instead. A ride-matching service that is the only class holding lists of drivers and exposing the operation to request a ride fits this exactly: Driver and Passenger objects never hold references to each other at all. If they referenced each other directly instead, every change to how matching, notification, or ride lifecycle worked would risk touching both classes, and the coupling between every driver and every passenger they might ever interact with would grow unmanageable as the system scaled. Centralizing that coordination in one class keeps Driver and Passenger focused purely on representing a user, while all the matching logic lives in exactly one place.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Browse other categories →← Back to all Low-Level Design & Design Patterns questions