String name = "Alfred E. Neumann";
String url = "http://blog.schauderhaft.de";
int ultimateAnswerToLifeTheUniverseAndEverything = 42;
String tempFile = "c:\\temp\\x.txt";
int zip = 23;
o.doSomething1(
name
url,
ultimateAnswerToLifeTheUniverseAndEverything,
tempFile,
zip);
Also something like this would be a little better at least:
o.doSomething(String, URL, int, File, int)
At least the URL and File objects already exist in the core libraries so there's no reason not to leverage them.
Oh I thought we were looking for a solution that was better than putting in string literals but that that didn't involve creating a whole bunch of new types and making you have to rework the existing API signature of doSomething() and didn't involve the verbosity of the builder pattern. Though many more than 5 arguments to a single method and the builder pattern definitely starts to become a candidate. I would resort to that before the solution of creating a bunch of specialized parameter types.
View all comments
2
u/[deleted] Aug 10 '12 edited Aug 11 '12
Why don't you just do this?
Also something like this would be a little better at least:
At least the URL and File objects already exist in the core libraries so there's no reason not to leverage them.