Class Observer
java.lang.Object
org.puremvc.java.patterns.observer.Observer
- All Implemented Interfaces:
IObserver
public class Observer extends java.lang.Object implements IObserver
A base IObserver implementation.
An Observer is an object that encapsulates information
about an interested object with a method that should
be called when a particular INotification is broadcast.
In PureMVC, the Observer class assumes these responsibilities:
- Encapsulate the notification (callback) method of the interested object.
- Encapsulate the notification context (this) of the interested object.
- Provide methods for setting the notification method and context.
- Provide a method for notifying the interested object.
- See Also:
View,Notification
-
Constructor Summary
Constructors Constructor Description Observer(java.util.function.Consumer<INotification> notifyMethod, java.lang.Object notifyContext)Constructor. -
Method Summary
Modifier and Type Method Description booleancompareNotifyContext(java.lang.Object object)Compare an object to the notification context.protected java.lang.ObjectgetNotifyContext()Get the notification context.protected java.util.function.Consumer<INotification>getNotifyMethod()Get the notification method.voidnotifyObserver(INotification notification)Notify the interested object.voidsetNotifyContext(java.lang.Object notifyContext)Set the notification context.voidsetNotifyMethod(java.util.function.Consumer<INotification> notifyMethod)Set the notification method.
-
Constructor Details
-
Observer
public Observer(java.util.function.Consumer<INotification> notifyMethod, java.lang.Object notifyContext)Constructor.
The notification method on the interested object should take one parameter of type
INotification- Parameters:
notifyMethod- the notification method of the interested objectnotifyContext- the notification context of the interested object
-
-
Method Details
-
compareNotifyContext
public boolean compareNotifyContext(java.lang.Object object)Compare an object to the notification context.
- Specified by:
compareNotifyContextin interfaceIObserver- Parameters:
object- the object to compare- Returns:
- boolean indicating if the object and the notification context are the same
-
notifyObserver
Notify the interested object.
- Specified by:
notifyObserverin interfaceIObserver- Parameters:
notification- theINotificationto pass to the interested object's notification method.
-
getNotifyContext
protected java.lang.Object getNotifyContext()Get the notification context.
- Returns:
- the notification context (
this) of the interested object.
-
setNotifyContext
public void setNotifyContext(java.lang.Object notifyContext)Set the notification context.
- Specified by:
setNotifyContextin interfaceIObserver- Parameters:
notifyContext- the notification context (this) of the interested object.
-
getNotifyMethod
Get the notification method.
- Returns:
- the notification (callback) consumer function of the interested object.
-
setNotifyMethod
Set the notification method.
The notification method should take one parameter of type
INotification.- Specified by:
setNotifyMethodin interfaceIObserver- Parameters:
notifyMethod- the notification (callback) consumer function of the interested object.
-