|
The VariableValue pattern defines a new instance variable (i.e., an attribute) and its access methods for an object.
An object should have direct access to its local data. Other objects may access via access-methods only. This serves two aims: namely, encapsulation and safety.
Data will be encapsulated because only the Object itself knows how an item is implemented, external objects only see external representations.
Safety is necessary to keep control on accessing, i.e., range checks or multiple write protections can be implemented.
Usually, this pattern will be used implicit by other patterns defining participants which are attributes.
The target object will contain a new attribute and methods to access it. In Smalltalk, a variable named v it would result in methods v (get) and v: (set).

Access to instance variables must only be available by corresponding methods.
It seems suggestive to build subpattern for Protected Variables using semaphores or monitor-concepts to save the variables on multiple access. (ProtectedVariableValue )
"Return attributes value." ^{variable}
"Set attributes value." ^{variable} := value
Pattern VariableValue Category basic Description VariableValue.html ObjectType use target Attribute implement variable End