Object Oriented Software Engineering   View all facts   Glossary   Help
subject > pattern > design pattern > read-only interface
Next design patternrelated pattern    Updesign pattern    Previous design patternproxy   

read-only interface
subjectfact 
read-only interfacehas definition A pattern in which an interface is used to restrict which classes have privileges to call update methods of a class2001-08-30 14:57:13.0
has antipatterns making the read only class a subclass of the «Mutable» class, overriding all methods that modify properties, such that they throw an exception2001-08-30 14:57:13.0
has context
  • You sometimes want certain privileged classes to be able to modify attributes of objects that are otherwise immutable.
2001-08-30 14:57:13.0
has forces 2001-08-30 14:57:13.0
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?2001-08-30 14:57:13.0
has solution
  1. 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.
  2. All classes that need to modify the class, often called «Mutator» classes, must be put in this package.
  3. 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.
  4. The «Mutable» class implements the «ReadOnlyInterface».
2001-08-30 14:57:13.0
is a subtopic of 6.11 - The Read-Only Interface Pattern2001-08-30 14:57:13.0
is an instance of design pattern2001-08-30 14:57:13.0
design patternhas 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
has related patterns zero or more related design patterns2001-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 patternrelated pattern    Updesign pattern    Previous design patternproxy