Encyclopedia > Mutable object

  Article Content

Immutable object

Redirected from Mutable 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
Wheatley Heights, New York

... and 15.9% are non-families. 13.0% of all households are made up of individuals and 5.2% have someone living alone who is 65 years of age or older. The averag ...

 
 
 
This page was created in 29 ms