- Inherits from:
- (com.apple.client.eocontrol) Object
(com.apple.yellow.eocontrol) NSObject
- Package:
- com.apple.client.eocontrol
- com.apple.yellow.eocontrol
EOObserverCenter is the central player in EOControl's change tracking mechanism. EOObserverCenter records observers and the objects they observe, and it distributes notifications when the observable objects change. For an overview of the change tracking mechanism, see "Tracking Enterprise Objects Changes" in the introduction to the EOControl Framework.
You don't ever create instances of EOObserverCenter. Instead, the class itself acts as the central manager of change notification, registering observers and notifying them of changes. The EOObserverCenter API is provided entirely in static methods.
Objects that directly observe others must implement the EOObserving interface,
which consists of the single method objectWillChange.
To register an object as an observer, invoke EOObserverCenter's addObserver with the observer and
the object to be observed. Once this is done, any time the observed object
invokes its willChange method, the observer is
sent an objectWillChange
message informing
it of the pending change. You can also register an observer to be
notified when any object changes using addOmniscientObserver. This can be
useful in certain situations, but as it's very costly to deal
out frequent change notifications, you should use omniscient observers
sparingly. To unregister either kind of observer, simply use the
corresponding remove...
method.
Objects that are about to change invoke willChange, a method defined by the
EOEnterpriseObject interface. The implementations of this method
invoke EOObserverCenter's notifyObserversObjectWillChange,
which sends an objectWillChange message
to all observers registered for the object that's changing, as
well as to any omniscient observers. notifyObserversObjectWillChange
optimizes
the process by suppressing redundant objectWillChange
messages
when the same object invokes willChange several times in a row
(as often happens when multiple properties are changed). Change
notification is immediate, and takes place before the
object's state changes. If you need to compare the object's
state before and after the change, you must arrange to examine the
new state at the end of the run loop.
You can suppress change notification when necessary, using
the suppressObserverNotification and enableObserverNotification methods.
While notification is suppressed, neither regular nor omniscient observers
are informed of changes. These methods nest, so you can invoke suppressObserverNotification
multiple
times, and notification isn't re-enabled until a matching number
of enableObserverNotification
message have
been sent.
- Registering and unregistering observers
- addObserver
- removeObserver
- addOmniscientObserver
- removeOmniscientObserver
- Notifying observers of change
- notifyObserversObjectWillChange
- Getting observers
- observersForObject
- observerForObject
- Suppressing change notification
- suppressObserverNotification
- enableObserverNotification
- observerNotificationSuppressCount
public static void
addObserver
(
EOObserving anObserver,
Object anObject)
See Also: removeObserver
public static void
addOmniscientObserver
(EOObserving anObserver)
objectWillChange
message
with a null argument.See Also: addObserver, removeOmniscientObserver
public static void
enableObserverNotification
()
public static void
notifyObserversObjectWillChange
(Object anObject)
If an observer wants to ensure that it receives notification the next time the last object to change changes again, it should use the statement:
EOObserverCenter.notifyObserversObjectWillChange(null);
An observable object (typically an enterprise object) invokes this method from its willChange implementation, so you should never have to invoke this method directly.
See Also: suppressObserverNotification, addObserver, addOmniscientObserver
public static EOObserving
observerForObject
(
Object anObject,
Class aClass)
public static int
observerNotificationSuppressCount
()
See Also: enableObserverNotification
public static NSArray
observersForObject
(Object anObject)
public static void
removeObserver
(
EOObserving anObserver,
Object anObject)
See Also: addObserver
public static void
removeOmniscientObserver
(EOObserving anObserver)
See Also: removeObserver, addOmniscientObserver
public static void
suppressObserverNotification
()