Created
April 12, 2013 09:51
-
-
Save moea/5370923 to your computer and use it in GitHub Desktop.
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
package com.novoda.example.MemoryLeaker; | |
import java.util.HashSet; | |
import java.util.Set; | |
public class ToyMessageBus { | |
private static ToyMessageBus instance; | |
private final Set<Object> listeners = new HashSet<Object>(); | |
private ToyMessageBus() {} | |
public static ToyMessageBus getInstance() { | |
// implementing this method correctly would require a separate blog post. | |
if(instance == null) { | |
instance = new ToyMessageBus(); | |
} | |
return instance; | |
} | |
public void register(Object o) { | |
listeners.add(o); | |
} | |
public void unregister(Object o) { | |
listeners.remove(o); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment