Reputation: 141
In a program with separated UI from business logic; I have a Garage, containing a list of Vehicle(licensePlate, coniditionOfVehicle)
I want to allow users of Garage to receive a list of all the licensePlates at a specific given conditionOfVehicle.
what should be the return type of the method? IList of string (exactly what the requirement states) vs IList of Vehicle (allowing for the client to see more properties of the car, thereby improving extensibility)
are we even allowed to return a Vehicle? this would allow the user to change things we might not want him to. (assume that the client has access to "Vehicle", as it is using a Builder to receive a Vehicle, and then calls the Garage.AddVehicle(vehicle) to add it to the garage)
Thanks
Upvotes: 2
Views: 89
Reputation: 236188
There is a YAGNI (You Arent Gonna Need It) principle which states:
Always implement things when you actually need them, never when you just foresee that you need them.
If requirement says 'users need list of licensePlates' then simply return what users need without trying to foresee what they might need. Otherwise you are wasting time on forecasting, you are adding possible problems (changing of vehicles by user), you are making your code unexpected both for users (they expect licensePlates) and for maintainers (they don't know where new requirement come from), and worst thing - new 'feature' might be not used by users.
Another principle which you are trying to violate by returning whole vehicle instance is KISS (Keep It Simple, Stupid):
If you have a choice between a simple solution and a complex one, then opting for complexity would be stupid.
Returning list of strings is more simple solution, which satisfies requirements. There is no need to add needless complexity to your system.
Upvotes: 2