I've been using Amazon Glacier via the Amazon Java SDK.
I'm struck that parameters are passed around via an object, rather than as individual parameters.
For example, to retrieve the output of a job, where the parameters are Vault, JobId,range, the following technique is used:
client.getJobOutput(new GetJobOutputRequest(Vault, JobId, range));
Instead of:
client.getJobOutput(Vault, JobId, range);
What are the pros and cons of the two approaches?
Pros:
- If your method takes many parameters, using a parameter object makes the method signature sane.
- If you want to take additional parameters for the method later, using a parameter object means that you just have to add another field in the param object and the method signature need not change.
- If you want a batch version of the method, just pass a list of param objects.
Cons:
- Extra verbosity
- Another level of indirection
来源:https://stackoverflow.com/questions/12189236/advantage-of-java-pattern-where-method-takes-object-as-a-parameter-instead-of-in