Building big, immutable objects without constructors having long parameter lists
Posted
by Malax
on Stack Overflow
See other posts from Stack Overflow
or by Malax
Published on 2010-05-17T12:21:06Z
Indexed on
2010/05/17
22:40 UTC
Read the original article
Hit count: 486
Hi StackOverflow!
I have some big (more than 3 fields) Objects which can and should be immutable. Every time I run into that case i tend to create constructor abominations with long parameter lists. It doesn't feel right, is hard to use and readability suffers.
It is even worse if the fields are some sort of collection type like lists. A simple addSibling(S s)
would ease the object creation so much but renders the object mutable.
What do you guys use in such cases? I'm on Scala and Java, but i think the problem is language agnostic as long as the language is object oriented.
Solutions I can think of:
- "Constructor abominations with long parameter lists"
- The Builder Pattern
Thanks for your input!
© Stack Overflow or respective owner