Created
May 7, 2013 13:47
-
-
Save jagwire/5532700 to your computer and use it in GitHub Desktop.
A generic decorator for Observable objects.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface Obj { | |
protected void doSomething(); | |
} | |
public class ObjImpl implements Obj { | |
protected void doSomething() { | |
int x = 5*5; | |
} | |
} | |
public abstract class Observable { | |
Set<Observer> observers; | |
public void addObserver(Observer observer); | |
public void removeObserver(Observer observer); | |
public void updateObservers(); | |
} | |
public class ObservableObj extends Observable implements Obj { | |
private Obj obj; | |
public ObservableObj(Obj obj) { | |
this.obj = obj; | |
} | |
protected void doSomething() { | |
super.doSomething(); | |
updateObservers(); | |
} | |
} | |
public class ObservableFactory<I> { | |
public I getObservable(Class<I> observableClass); | |
} | |
Runnable observableRunnable; = getObservable(Runnable.class); | |
r.addObserver().run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment