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
Flapper

... as sports or higher education. World War I forced women to break even more gender barriers by entering the workforce to replace the large numbers of men fighting overseas. ...

 
 
 
This page was created in 37.1 ms