PATH  WebObjects 4.0 Documentation > What's New in EOF 3.0

Table of Contents Previous Section

Changes to Key-Value Coding

In release 3.0, Enterprise Objects Framework makes slight changes to key-value coding:

The new key-value coding API is summarized in the following table:
Key-Value Coding Primitives
valueForKey: The search order for resolving the provided key has changed to the following: method getKey, key
method _getKey, _key
instance variable _key, key
takeValue:forKey:(Objective-C) takeValueForKey (Java) The search order for resolving the provided key has changed to the following: method setKey, _setKey
instance variable key, _key
storedValueForKey: The search order for resolving the provided key has changed to the following: method _getKey, _key
instance variable _key, key
method getKey, key
takeStoredValue:forKey:(Objective-C) takeStoredValueForKey (Java) The search order for resolving the provided key has changed to the following: method _setKey, _key
instance variable key, setKey

Stored Value Methods

The stored value methods, storedValueForKey: and takeStoredValue:forKey: (storedValueForKey and takeStoredValueForKey in Java), are used by the framework when accessing properties of an enterprise object to get or set properties for state storage and restoration (either from the database or to an in-memory snapshot). This access is considered private to the enterprise object and is invoked by the Framework to effect persistence on the object's behalf.

On the other hand, the basic key-value coding methods, valueForKey: and takeValue:forKey: (valueForKey and takeValueForKey in Java), are the public interface to an enterprise object. They are invoked by clients external to the object (such as for interactions with user interface or other business object logic).

Enterprise object classes can take advantage of this distinction to perform additional processing in accessor methods except when the object is being initialized with values from an external store. For instance, suppose an object wanted to update a total whenever the bonus was set:

void setBonus(double newBonus) {
willChange();
_total += (newBonus - _bonus);
}
This code should be activated when the object is updated with values provided by a user through the application's user interface, but not when the bonus property is restored from the database. Since the Framework restores the property using takeStoredValue:forKey: (takeStoredValueForKey in Java) and since this method accesses the _bonus instance variable in preference to calling the accessor, the unnecessary (and possibly harmful) recomputation of _total is avoided. If the object actually wants to intervene when a property is set from the database, it has two options:

Table of Contents Next Section