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 Car and ParkingLot, where ParkingLot holds a map from car registration number to Car objects. One of the methods of ParkingLot is 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:
Have
getCarvalidate the registration number. It can then return anot_validerror if the number is invalid. The downside as I see it is that theParkingLotobject does validation of parameters which logically belong toCar.Have
getCarjust check whether the registration number is in the map. The downside is that the only possible error would benot_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?