Object Oriented Software Engineering   View all facts   Glossary   Help
subject > pattern > design pattern > immutable
Next design patternobserver    Updesign pattern    Previous design patterngeneral hierarchy   

immutable
subjectfact 
immutablehas definition A pattern in which the instances of a class cannot change state after creation2001-08-30 14:55:53.0
has context 2001-08-30 14:55:53.0
has forces html>
  • The immutability must be enforced.
  • There must be no loopholes that would allow 'illegal' modification of an immutable object.
2001-08-30 14:55:53.0
has problem How do you create a class whose instances are immutable?2001-08-30 14:55:53.0
has related patterns Read-Only Interface pattern provides the same capability as immutable, except that certain privileged classes are allowed to make changes to instances.2001-08-30 14:55:53.0
has solution
  1. Ensure that the constructor of the immutable class is the only place where the values of instance variables are set or modified.
  2. If a method that would otherwise modify an instance variable must be present, then it has to return a new instance of the class.
2001-08-30 14:55:53.0
is a subtopic of 6.10 - The Immutable Pattern2001-08-30 14:55:53.0
is an instance of design pattern2001-08-30 14:55:53.0
design patternhas antipatterns zero or more antipatterns - solutions that are inferior or do not work in this context with the reason for their rejection2001-08-30 14:55:16.0
has name2001-08-30 14:55:16.0
has references one or more references which indicate who developed or inspired a pattern2001-08-30 14:55:16.0
should be illustrated using a simple diagram2001-08-30 14:55:16.0
should be written using a narrative writing style2001-08-30 14:55:16.0
patternshould be as general as possible2001-08-30 14:56:56.0
should be described in an easy-to-understand form so that people can determine when and how to use it2001-08-30 14:56:56.0
should contain a solution that has been proven to effectively solve the problem in the indicated context2001-08-30 14:56:56.0

Next design patternobserver    Updesign pattern    Previous design patterngeneral hierarchy