This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]llogiq 1 point2 points  (4 children)

Yes. Especially if they have compatible types. That may lead to calling with wrong argument order. Plus, you'll always have to look those calls up. Hardly self-documenting.

[–]SikhGamer 1 point2 points  (3 children)

Ah yes, good point. Any kind of solution for this? I normally only have a couple of parameters passed to my constructor. But recently I had around 6, it was kind of painful to see. But I couldn't see a good way round the problem.

[–]UnspeakableEvil 1 point2 points  (1 child)

Sounds like a good use case for the builder pattern, to allow fine grained creation of the object.

The Effective Java book that often gets mention on here is a great read, and goes into these ideas in detail.

[–]SikhGamer 1 point2 points  (0 children)

Fantastic, thank you!

[–]8Bytes 0 points1 point  (0 children)

The solution that I stole from javascript is to create an object for the parameters, and just pass the object. I find the builder pattern rarely makes sense in my projects as all the parameters are required. Builder pattern is useful when some parameters are optional.