|
WebObjects 5.2 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.webobjects.foundation.NSNotification
NSNotification objects encapsulate information so that it can be broadcast to other objects by an NSNotificationCenter object.
The standard way to pass information between objects is method invocation -- one object invokes the method of another object. However, method invocation requires that the object invoking the method knows which object to invoke the method on, and what messages it responds to. At times, this tight coupling of two objects is undesirable -- most notably because it would join together two otherwise independent subsystems. For these cases, a broadcast model is introduced: an object posts a notification, which is dispatched to the appropriate observers through an NSNotificationCenter object, or simply notification center.
This notification model frees an object from concern about what objects it should send information to. Any object may simply post a notification without knowing what objects -- if any -- are receiving the notification. However, objects receiving notifications will need to know at least the notification name, and possibly the type of information the notification contains. The notification center takes care of broadcasting notifications to registered observers. Another benefit of this model is to allow multiple objects to listen for notifications, which would otherwise be cumbersome.
Any object may post a notification. Other objects can register themselves as observers to receive notifications when they are posted. The object posting the notification, the object included in the notification, and the observer of the notification may all be different objects or the same object.
You can create a notification object with the constructor, however,
generally, you will not need to create notifications directly. The NSNotificationCenter
method postNotification
allows convenient posting of a notification
without creating it first.
An NSNotification object (referred to as a notification) contains a name
,
an object
, and a userInfo
. The name
is a tag
identifying the notification. The object
is any object that the poster
of the notification wants to send to observers of that notification, although typically
it is the object that posted the notification. The userInfo
is an
NSDictionary used to store other information the sender of the notification may
want to pass to observers.
NSNotification objects are immutable.
NSNotificationCenter
,
NSNotificationCenter.postNotification(NSNotification notification)
, Serialized FormInner classes inherited from class com.webobjects.foundation.NSCoding |
NSCoding.Support |
Constructor Summary | |
NSNotification(String name,
Object object)
Initializes and returns a notification with name name ,
object object , and an empty userInfo . |
|
NSNotification(String name,
Object object,
NSDictionary userInfo)
Initializes and returns a notification with name name ,
object object , and arbitrary user information
userInfo . |
Method Summary | |
Class |
classForCoder()
Returns the class that should be used for encoding the receiver in an NSCoder. |
static Object |
decodeObject(NSCoder coder)
Creates an NSNotification from the data in coder . |
void |
encodeWithCoder(NSCoder coder)
Encodes the receiver using coder . |
boolean |
equals(Object other)
Compares the receiving NSNotification object to other . |
int |
hashCode()
Provide an appropriate hash code useful for storing the receiver in a hash-based data structure. |
String |
name()
Returns the name of the notification. |
Object |
object()
Returns the object associated with the notification. |
String |
toString()
Returns a string representation of the receiver including its name object and userInfo . |
NSDictionary |
userInfo()
Returns the notification's userInfo dictionary. |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public NSNotification(String name, Object object, NSDictionary userInfo)
name
,
object object
, and arbitrary user information
userInfo
. The userInfo
parameter may
be null
; if so, the userInfo
method
will return an empty NSDictionary. name
may not
be null
.name
- String name of the notificationobject
- Object associated with the notificationuserInfo
- NSDictionary of arbitrary informationpublic NSNotification(String name, Object object)
name
,
object object
, and an empty userInfo
.
name
may not be null.name
- name attached to the objectobject
- the current notification objectMethod Detail |
public Class classForCoder()
classForCoder
in interface NSCoding
NSCoder
,
NSCoding
public static Object decodeObject(NSCoder coder)
coder
.coder
- an NSCoder containing data that can be used to construct
a new NSNotificationcoder
NSCoder
,
NSCoding
public void encodeWithCoder(NSCoder coder)
coder
.encodeWithCoder
in interface NSCoding
coder
- the NSCoder which should be used to encode the receiverNSCoder
,
NSCoding
public boolean equals(Object other)
other
.
If other
is an NSNotification and the contents of other
are equal to the contents of the receiver, this method returns true
.
If not, it returns false
.
Two notifications are equal if their name
and userInfo
are equal and their object
have identical references.
equals
in class Object
other
- the object to be compared to the current objecttrue
when the contents of the objects compared
are same, false
otherwisename()
,
object()
,
userInfo()
public int hashCode()
hashCode
in class Object
public String name()
Notification names can be any string. To avoid name collisions, however, you might want to use a prefix that's specific to your application.
NSSelector
,
NSNotificationCenter
,
NSUndoManager
public Object object()
null
, or another object entirely.
Typically, you invoke this method on the notification object passed
to your notification-handler method. This notification-handler method
is the method applied by the NSSelector registered with NSNotificationCenter
when the observer registered to receive the notification. NSSelector
,
NSNotificationCenter
public String toString()
name
object and userInfo
.toString
in class Object
public NSDictionary userInfo()
userInfo
dictionary. This NSDictionary
stores any additional information that objects receiving the notification might use.
The NSDictionary is empty if no userInfo dictionary was specified when the notification
was created.
|
Last updated Fri Feb 21 13:15:00 PST 2003. | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |