Immutable object

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
(New page: An immutable object is one in which the value or state can not be changed. The value is set when the object is created. If the value of the object needs to be changed then the object is r...)
 
Line 2: Line 2:
  
 
The value is set when the object is created. If the value of the object needs to be changed then the object is replaced by an object containing the new value. The string object in Java is an example of an immutable object. Any string operations in Java return a new object containing the result of the operation. Using immutable objects removes synchronisation problems that can occur in multi threaded programmes. It also removes worries on some level about side effects.
 
The value is set when the object is created. If the value of the object needs to be changed then the object is replaced by an object containing the new value. The string object in Java is an example of an immutable object. Any string operations in Java return a new object containing the result of the operation. Using immutable objects removes synchronisation problems that can occur in multi threaded programmes. It also removes worries on some level about side effects.
 +
 +
Many concepts will not work without the concept of immutable objects such as [[flyweight]] and the "canonical representation" mechanism for strings in Java.
 +
 +
==See Also==
 +
 +
[[Getters and setters]]

Revision as of 06:25, 5 October 2008

An immutable object is one in which the value or state can not be changed.

The value is set when the object is created. If the value of the object needs to be changed then the object is replaced by an object containing the new value. The string object in Java is an example of an immutable object. Any string operations in Java return a new object containing the result of the operation. Using immutable objects removes synchronisation problems that can occur in multi threaded programmes. It also removes worries on some level about side effects.

Many concepts will not work without the concept of immutable objects such as flyweight and the "canonical representation" mechanism for strings in Java.

See Also

Getters and setters

Personal tools