BNZAtomicPropertyChange
Abstract: A generic implementation of BNZAtomicChange that can be used for simple one-valued
properties (i.e., no lists or other collections are supported)
The BNZAtomicPropertyChange is a generic implementation for changes on
properties that are not lists or arrays or other collections.
It implements the BNZAtomicChange protocol and provides static helper methods
that greatly simplify the implementation of transactional objects.
For setter and getter methods of an object, a static method of BNZAtomicChange is provided
to gain all the functionality like transactions and showing changes within the
same thread but hiding them from other threads until committed.
The convention to use this generic change implementation (especially the easy-to-use
static methods) is as follows:
for each property like "firstName" provide a public setter "setFirstName:" and getter "firstName"
(however, for readonly or writeonly, a getter or setter may be ommitted and the exact names are not really important)
Implement the getter and setter like in the example below
Provide accessor methods (also getter and setter) that allow the change object to access the
iVar directly. Naming scheme is: "setFirstName_internal:" and "firstName_internal" These names are important,
if you use the static helper methods of this class. If the accessors are named differently, directly
use the initWithTarget:newValue:setterMethod:getterMethod:andChangeType: instead.
Note: it may be possible to get rid of the accessor methods by providing some pointers to the fields. However,
there still may be a reason to encapsulate field access because some fields may have to be calculated or reading/setting
a field may trigger some other things.
Example implementation of an transactional object's setter and getter:
- setFirstName:(NSString*)name {
[BNZAtomicPropertyChange createAtomicChangeOfProperty:"firstName" onTarget:self toNewValue:name];
return self;
}
- (NSString*)firstName {
return [BNZAtomicPropertyChange transactionalValueForProperty:"firstName" ofTarget:self];
}
//internal methods for communication between change objects and the person, not part of the header!
- (void)setFirstName_internal:(NSString*)newName {
firstName = newName;
}
- (NSString*)firstName_internal {
return firstName;
}
(Last Updated 8/31/2006)
HTML documentation generated by HeaderDoc