This question is a clearer version of a question I posted on SO.
I have a C++
Planner object with a method that computes a
Route from a start point to a destination point.
Planner is the owner of the computed
Now, I have a second method (call it
TestRoute), that takes the route object and tells if the destination is reachable from the start point, and if not, tries to find a route that passes through fuelling stations.
The original implementation of
TestRoute was to return a
Route pointer when the trip is feasible (with or without refuelling), and NULL in case of failure:
- if a refuelling is necessary,
TestRoutereturns a pointer to the new Route;
- if no refuelling is necessary, it returns a pointer to a copy of the original Route, since its owner is
In these both cases, it is up to the caller of
TestRouteto destruct the returned
Well, now, a colleague of mine wants the method returns
NULL when the route is feasible without refuelling, to avoid useless copy and destruction.
So the method would return:
- NULL in case of failure
- a pointer to a
Routein case of success when a new
- NULL in case of success (!!) when no refuelling is necessary.
It sounds to me like a terrible design. May I have some opinion?