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
East Islip, New York

... town. The population density is 1,322.5/km² (3,428.5/mi²). There are 4,661 housing units at an average density of 437.9/km² (1,135.1/mi²). The racial ...

 
 
 
This page was created in 27 ms