I have a question which I'm not sure how to generalize and ask properly, so I'll try with an example.
Suppose that I design a parking lot management system. In my system, I have the objects
ParkingLot holds a map from car registration number to
Car objects. One of the methods of
getCar(n), which can fail if
n is not a valid registration number, or if a car with such registration number doesn't exist in the parking lot.
I have two options:
getCarvalidate the registration number. It can then return a
not_validerror if the number is invalid. The downside as I see it is that the
ParkingLotobject does validation of parameters which logically belong to
getCarjust check whether the registration number is in the map. The downside is that the only possible error would be
not_found, so the caller wouldn't be able to know whether the function failed because the registration number was invalid, or the car just isn't there.
Is there any preferred way to go with this? Perhaps there's a superior solution which will allow to save the extra validation, which increases coupling, and still provide full information for the caller?