Encyclopedia > Immutable object

  Article Content

Immutable object

In computer science, an immutable object, as opposed to a mutable object, is a kind of object whose internal states cannot be modified in object oriented programming (OOP).

In some languages, objects are handled as a reference rather than a concrete value. Many OOP langauges take that scheme, including Java programming language and Ruby programming language. In that case, it matters whether the state of object can vary or not.

Handling mutable objects is usually more cumbersome than immutable ones. To avoid surprising changes, you need to use a defensive copy[?]. This trick often slows down runtime performance.

It is recommented that immutable data should always be passed to the constructor. It should not be set via an accessor. See accumulate and fire for a description of this problem.

Strings or other concrete objects are typically expressed as immutable object to improve readibility and runtime efficiency in object-oriented programming. In Python and Java, strings are immutable objects while Java also has a class StringBuffer as mutable object.

The aritcle contains materials partly from Perl Design Patterns Book.

External Links



All Wikipedia text is available under the terms of the GNU Free Documentation License

 
  Search Encyclopedia

Search over one million articles, find something about almost anything!
 
 
  
  Featured Article
Northwest Harbor, New York

... Demographics As of the census of 2000, there are 3,059 people, 1,181 households, and 818 families residing in the town. The population density is 81.3/km² ...

 
 
 
This page was created in 38 ms