4

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?

Steffen Opel
  • 63,899
  • 11
  • 192
  • 211
Alan
  • 2,140
  • 1
  • 24
  • 30
  • [Clean Code](http://stackoverflow.com/questions/174968/how-many-parameters-are-too-many/175035#175035), per Uncle Bob. – EthanB Aug 30 '12 at 03:07

1 Answers1

9

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
Abhinav Sarkar
  • 23,534
  • 11
  • 81
  • 97
  • +1 Method signature extensibility in public methods (e.g. web-services). – EthanB Aug 30 '12 at 03:06
  • As for point 2. It doesn't matter if you need to add parameter to method or to param-class. You still need to recompile something and provide new interface to client. For web-services clients need to generate new stubs from WSDL. Of course you can use a `Map` but this approach is just very wrong. – Piotr Gwiazda Sep 28 '12 at 07:03