read-only interface | has definition A pattern in which an interface is used to restrict which classes have privileges to call update methods of a class |  |
has antipatterns making the read only class a subclass of the «Mutable» class, overriding all methods that modify properties, such that they throw an exception |  |
has context - You sometimes want certain privileged classes to be able to modify attributes of objects that are otherwise immutable.
|  |
has forces |  |
has problem 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? |  |
has solution - 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».
|  |
is a subtopic of 6.11 - The Read-Only Interface Pattern |  |
is an instance of design pattern |  |
design pattern | has name |  |
has references one or more references which indicate who developed or inspired a pattern |  |
has related patterns zero or more related design patterns |  |
should be illustrated using a simple diagram |  |
should be written using a narrative writing style |  |
pattern | should be as general as possible |  |
should be described in an easy-to-understand form so that people can determine when and how to use it |  |
should contain a solution that has been proven to effectively solve the problem in the indicated context |  |