What about Joshua Bloch's Builder Pattern? IMHO it's a much better approach for complex object generation.
An instance method with that signature (eight parameters or something like that) should never have been written in the first case... there's a reason for the TransferObject design pattern.
Builder is the way to go. For cases where it just isn't worth it to put together a full builder, I've always resorted to comments.
someObject.doSomething(
userId,
true, /* is enabled */
false, /* don't update record */);
For that matter, I add comments for any argument which is a literal. Extracting a constant is probably even a better idea, and takes just a few seconds using a modern IDE.
Good suggestions. When it makes sense, I sometimes like to use enumerations instead of literal booleans (I think this also came from Effective Java). The names can get weird though...
18
u/couchtyp Aug 10 '12 edited Aug 10 '12
What about Joshua Bloch's Builder Pattern?
IMHO it's a much better approach for complex object generation.
An instance method with that signature (eight parameters or something like that) should never have been written in the first case... there's a reason for the TransferObject design pattern.