Questions tagged [immutability]

Immutability is about having objects that cannot be changed.

Immutability is about having objects that cannot be changed.

169 questions
6
votes
2 answers

What's wrong with mutability and can it be desirable?

Possible Duplicate: At what point do immutable classes become a burden? This is something I never understood. When learning C++, for instance, I had lots of headaches with const issues, as it added lots of complexity to programming. Why is…
Dokkat
  • 199
3
votes
2 answers

Changing immutable objects how does this work?

I have seen examples where even though the object is immutable there are situations in which we need to update some fields and as I understand it, the object is passed to a constructor which makes a copy with updated values but the original is not…
Jeff
  • 149
3
votes
3 answers

How to make complex objects immutable?

The example I'm about to give is for the PHP language, but I think this scenario applies to most languages. Let's say I have an object called Response and I want it to be immutable. Every method should return a new instance rather than modifying…
mpen
  • 1,889
2
votes
5 answers

Trying to understand the benefits of immutability in imperative programming

I'm learning about immutability (specifically in C#) and I can't understand the examples out there stating that making an object immutable brings real benefits (besides a shared object in a multi threaded environment, which the benefits are pretty…
-1
votes
2 answers

Immutability and encapsulating state changing behavior

Immutable objects In object-oriented and functional programming, an immutable object (unchangeable[1] object) is an object whose state cannot be modified after it is created Wikipedia (https://en.wikipedia.org/wiki/Immutable_object) Code example…
Stefan
  • 87
  • 1
  • 7