read-only interface | - Create a «Mutable» class as you would create any other class, except make sure it is not public; this ensures that it can be accessed only from its package.
- All classes that need to modify the class, often called «Mutator» classes, must be put in this package.
- Then create a public interface we will call the «ReadOnlyInterface», that has only the read-only operations of «Mutable» - i.e. only operations that get its values.
- The «Mutable» class implements the «ReadOnlyInterface».
| - You sometimes want certain privileged classes to be able to modify attributes of objects that are otherwise immutable.
| | How do you create a situation where some classes see a class as read-only (i.e. the class is immutable) whereas others are able to make modifications? | A pattern in which an interface is used to restrict which classes have privileges to call update methods of a class | making the read only class a subclass of the «Mutable» class, overriding all methods that modify properties, such that they throw an exception | 6.11 - The Read-Only Interface Pattern | | design pattern |