public class BaseObservable extends Object implements IObservable
IObservable.
This implementation notifies the observers in a synchronous fashion. Note that this can cause trouble if you notify the observers while in a transactional context because once the notification is done it cannot be rolled back.
IObservable,
IObserver,
WeakReferenceObservable| Constructor and Description |
|---|
BaseObservable(IObservable observable) |
| Modifier and Type | Method and Description |
|---|---|
void |
addObserver(IObserver observer)
Attaches a observer to the Observable.
|
int |
countObservers()
Counts how many Observers were attached to this class.
|
void |
deleteObserver(IObserver observer)
Detaches a previously attached observer to the observable.
|
void |
deleteObservers()
Detaches all previously attached observer to the observable.
|
List<IObserver> |
getObservers()
Returns list of observers registered with the Observable.
|
void |
notifyObservers()
Notifies all attached observers about changes in the observable.
|
void |
notifyObservers(Object arg)
Notifies all attached observers about changes in the observable.
|
protected void |
wrappedNotify(IObserver observer,
IObservable observable,
Object arg)
This method is intended to encapsulate the notification semantics, in
order to let extended classes to implement their own version.
|
public BaseObservable(IObservable observable)
public void addObserver(IObserver observer)
IObservableaddObserver in interface IObservableobserver - The observer to attach to the observablepublic int countObservers()
IObservablecountObservers in interface IObservableIObserverpublic List<IObserver> getObservers()
IObservablegetObservers in interface IObservablepublic void deleteObserver(IObserver observer)
IObservabledeleteObserver in interface IObservableobserver - The observer to detach from the observablepublic void deleteObservers()
IObservabledeleteObservers in interface IObservablepublic void notifyObservers()
IObservablenotifyObservers in interface IObservablepublic void notifyObservers(Object arg)
IObservablenotifyObservers in interface IObservablearg - an arbitrary Object to be passed to the Observerprotected void wrappedNotify(IObserver observer, IObservable observable, Object arg)
The default notification simply does
observer.update(observable, arg);
observer - the observer.observable - the object to be observed.arg - additional arguments.Copyright © 2022. All rights reserved.