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 comparison table
Subject have solution have context have forces have problem has definition have antipatterns is a subtopic of is a kind of is an instance of
design pattern a contextone or more forcesa sentence or two explaining the main difficulty being tackledA pattern useful for the design of softwarezero or more antipatterns - solutions that are inferior or do not work in this context with the reason for their rejection6.1 - Introduction to Patternspattern 
read-only interface
  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».
  • 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 classmaking the read only class a subclass of the «Mutable» class, overriding all methods that modify properties, such that they throw an exception6.11 - The Read-Only Interface Pattern design pattern

Next design patternrelated pattern    Updesign pattern    Previous design patternproxy