Let's say I have a project that needs to do the following:
- Multiple calls to read from the database where each call is a different query and returns back a value object (just has getters/setters). Let's say we end receiving 20 value objects
- Perform some logic with the data from these value objects
I'm trying to brainstorm the best practice for parameters to my methods for the second bullet point given that some value objects might have more fields than what my methods need.
Let's say that I want to accomplish the second bullet point by having many classes that each do a portion of the work. Let's say one class happens to need 7 fields from one value object and 8 fields from another value object and that both value objects each have 30+ fields. I can think of 3 ways to do this:
Have my class take in the two value objects it needs as a parameter. The class will then call 15 getters and then do something with the fields. Take this same approach for the rest of my classes where they take in the value objects they need
Code up a new value object which only stores the 15 values that I need. Somewhere in my application I will have to do a mapping/conversion from these two value objects to my new value object. My class will call 15 getters and then do something with the fields. Take this same approach for the rest of my classes
Code up some huge value object that stores all of the data that I need for the entire second bullet point. We basically take all of our value objects and convert all the data we need to this huge value object. My class will then take in this huge value object. My class will call 15 getters and then do something with the fields. Each class that does a portion of the logic will take in this huge value object
Which is the best approach?
seems like the easiest approach. However, it feels weird having a class that asks for more information than it needs. Someone looking at the class might want to know why it asks for 60 fields if it is only going to use 15 of them.
seems to be by far the most complicated as it has many different mappings but each individual class ends up asking only for what it needs.