Created
June 8, 2016 05:22
-
-
Save mindwing/e7bab6ce6838cf165087845e6867d673 to your computer and use it in GitHub Desktop.
Agera Explained - 08.Incrementally Agerifying legacy code
This file contains hidden or 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 final class MyListenable extends SomeBaseClass implements Observable { | |
private final UpdateDispatcher updateDispatcher; | |
public MyListenable() { | |
// Original constructor code here... | |
updateDispatcher = Observables.updateDispatcher(new Bridge()); | |
} | |
// Original class body here... including: | |
public void addListener(Listener listener) { … } | |
public void removeListener(Listener listener) { … } | |
@Override | |
public void addUpdatable(Updatable updatable) { | |
updateDispatcher.addUpdatable(updatable); | |
} | |
@Override | |
public void removeUpdatable(Updatable updatable) { | |
updateDispatcher.removeUpdatable(updatable); | |
} | |
private final class Bridge implements ActivationHandler, Listener { | |
@Override | |
public void observableActivated(UpdateDispatcher caller) { | |
addListener(this); | |
} | |
@Override | |
public void observableDeactivated(UpdateDispatcher caller) { | |
removeListener(this); | |
} | |
@Override | |
public void onEvent() { // Listener implementation | |
updateDispatcher.update(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment