I’m just a junior developer but in about half a dozen projects I worked on there’s always this situation:
Service methods that take big objects as parameters, but often use just a little portion of them. Let me try to clarify with a little bit of code:
class WorkforceService { public void assignEmployeeToWorkplace(Workplace wp, Employee emp) { //this method just checks couple things that //may prevent assigning that employee to that workplace //if everything's ok employee is assigned } }
Difficulties that I have with the situation:
-
If I try to unit test this method, I need to create a full fledged workplace and employee object. These contain many other members and data, which may or may not be relevant to this method.
-
Auditing. Somewhere down the line I will be requested to audit these method calls. Those big parameters make it difficult to automate auditing, I can’t just serialize and write them to a log because they are big and contain irrelevant data to the method. I need to hand pick the data I need to save.
I’m wondering these:
1) Is it supposed to be like this?
2) If not, where is the problem? Are those objects unnecessarily big and service method is ok, or is it service method’s fault and somehow it should request only whatever it actually needs?