Immutability of big objects

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 12:30 UTC
Read the original article Hit count: 297

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:

  1. "Constructor abominations with long parameter lists"
  2. The Builder Pattern

Thanks for your input!

© Stack Overflow or respective owner

Related posts about object-oriented-design

Related posts about immutable