Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Advantage of Java Pattern where method takes Object as a parameter instead of individual parameters

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?

like image 934
Alan Avatar asked Jan 16 '23 16:01

Alan


1 Answers

Pros:

  1. If your method takes many parameters, using a parameter object makes the method signature sane.
  2. 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.
  3. If you want a batch version of the method, just pass a list of param objects.

Cons:

  1. Extra verbosity
  2. Another level of indirection
like image 96
Abhinav Sarkar Avatar answered Jan 18 '23 05:01

Abhinav Sarkar