An interface implemented by mutable objects whose state can be fully
locked. After an object is made readonly, its state can thereafter not ever
be modified again.
Ideally, well-behaved objects are always in a consistent state. However,
sometimes this is not feasible, and you will want to call several mutation
methods on objects that are otherwise intended to be immutable. When this
occurs, you have several options, for example, adding a utility class
containing a method like
MyObject MyObjectUtil.unmodifiableMyObject( MyObject object )
That is the approach taken in the Collections API (see
java.util.Collections.unmodifiableList(java.util.List) unmodifiableList() and others). The downside there is that you litter your class library with
small utility classes.
This interface offers an alternative that keeps the immutability support
encapsulated within the actual class.
author: Leo Simons version: $Id: ReadonlyEnabled.java,v 1.1 2004/03/23 13:37:56 lsimons Exp $ |