Dave Tolls wrote:Presumably the VehicleInfo class has fields that map to columns in the VehicleInformation table.
So create a VehicleInfo object with those values and return that.
Your REST framework should do the rest for you.
By the way, you should be using a PreparedStatement there and binding (setString()) for the licensePlate variable.
Paul Clapham wrote:You would start by defining a VehicleInfo class which models the data that you want to collect from the database. It's possible you may need other supporting classes as well -- your throwaway statement about "years" suggests that might be the case. Then when you have that done, you would write code which selects the relevant data and writes it to a VehicleInfo object -- or more than one VehicleInfo object, or one of them plus several other objects, or whatever your design turned out to be.
That's all that can be said so far; your initial question sounded reasonable enough but then you threw in some things which might imply that it's actually more complicated. However since we don't know much about your database tables or what you're expected to return, we can't really comment on those things.
Fred Victa wrote:Should I put the different years in a list, the different makes in another list, the different models in another list, and so on? Should my object contain multiple lists?
Junilu Lacar wrote:One little note: "Info" is one of those name suffixes that are kind of redundant and they lead your mind away from Object-Oriented thinking.
Consider the name VehicleInfo and compare it to just Vehicle
The former leads you to the kind of thinking where this class is all about information pertaining to a vehicle. That takes away from the biggest benefit of Object-Orientation, which is behavior. The fact that there is information about a vehicle embedded or encapsulated in this class should be secondary to the behavior that instances of this class can exhibit.
Other similar suffixes are "Data" as in "VehicleData" and "Details" as in "VehicleDetails".
If you go with just Vehicle for the name, it makes you focus less on the encapsulated information. That fact that there is information encapsulated in this class should be apparent when you look at the list of getters/setters available but your focus really should be on the object behavior.
Blueberry pie is best when it is firm and you can hold in your hand. Smell it. And smell this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|