EOObserverCenter
- Inherits from:
- NSObject
- Conforms to:
- NSObject
- (NSObject)
Declared in:
- EOControl/EOObserver.h
Class Description
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 class methods.
Registering an Observer
Objects that directly observe others must adopt the EOObserving protocol, which consists of the single method objectWillChange:. To register an object as an observer, invoke EOObserverCenter's addObserver:forObject: 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.
Change Notification
Objects that are about to change invoke willChange, a method that the Framework adds to NSObject. 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.
Method Types
- Registering and unregistering observers
- + addObserver:forObject:
- + removeObserver:forObject:
- + addOmniscientObserver:
- + removeOmniscientObserver:
- Notifying observers of change
- + notifyObserversObjectWillChange:
- Getting observers
- + observersForObject:
- + observerForObject:ofClass:
- Suppressing change notification
- + suppressObserverNotification
- + enableObserverNotification
- + observerNotificationSuppressCount
Class Methods
addObserver:forObject:
+ (void)addObserver:(id
<EOObserving>)anObserver
forObject:(id)anObject
See Also: + removeObserver:forObject:
addOmniscientObserver:
+ (void)addOmniscientObserver:(id
<EOObserving>)anObserver
See Also: + addObserver:forObject:, + removeOmniscientObserver:
enableObserverNotification
+ (void)enableObserverNotification
notifyObserversObjectWillChange:
+ (void)notifyObserversObjectWillChange:(id)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:nil];
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:forObject:, + addOmniscientObserver:
observerForObject:ofClass:
+ (id)observerForObject:(id)anObject
ofClass:(Class)aClass
observerNotificationSuppressCount
+ (unsigned int)observerNotificationSuppressCount
See Also: + enableObserverNotification
observersForObject:
+ (NSArray *)observersForObject:(id)anObject
removeObserver:forObject:
+ (void)removeObserver:(id
<EOObserving>)anObserver
forObject:(id)anObject
See Also: - addObserver:forObject:
removeOmniscientObserver:
+ (void)removeOmniscientObserver:(id
<EOObserving>)anObserver
See Also: + removeObserver:forObject:, + addOmniscientObserver:
suppressObserverNotification
+ (void)suppressObserverNotification