Skip navigation links


Implementation of the observer pattern.

See: Description

Package Description

Implementation of the observer pattern. Observers registers with an Observable using Observable#addObserver(Observer), and will receive notifications as a call to Observer#notify(Observable, Object).

Typical implementations of Observable will be delegating to a MultiCaster to do the boring observer registration and message dispatching.

Example of Observable:

 public class MyObservable implements Observable {
         public static class MyEvent {
                // ..
         private MultiCaster<:MyEvent> multiCaster = new MultiCaster<:MyEvent>(this);
         public void doStuff() {
                multiCaster.notify(new MyEvent());
         public void addObserver(Observer observer) {
         public List> getObservers() {
                return multiCaster.getObservers();
         public void removeObserver(Observer observer) {
And an observer that is notified when MyObservable.doStuff() is called:
 public class MyObserver implements Observer {
         public void notify(Observable sender, MyEvent message) {
                System.out.println("Receieved " + message + " from " + sender);
Example of usage:
                MyObservable observable = new MyObservable();
                MyObserver observer = new MyObserver();
Skip navigation links

Copyright © 2015–2016 The Apache Software Foundation. All rights reserved.