.... immutable object is an object whose state cannot be modified after it
is created. This is in contrast to a mutable object, which can be modified
after it is created....
The source (and examples): http://en.wikipedia.org/wiki/Immutable_object
immutable objects are significant because of how the compiler will
deal with them. for instance C# strings are immutable, so if you say
string s = "bl";
foreach (int i=0; i<10; i++)
s += "a";
s+= "h";
the end result is what you think it would be, but the compiler will be
creating lots more temporary strings in between.
"bla", "blaa", "blaaa" ... etc
if strings weren't immutable you wouldn't have as many temporary
objects, but things maintenance behind the scenes would be slower.
When objects are immutable the compiler has more assumptions to work
on and will be faster in the long run (assuming you avoid stuff like
the above). So if something is immutable you should be aware of
temporary object creation getting out of hand.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.