Building big, immutable objects without using constructors having long parameter lists
- by Malax
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!