Skip to content

Instantly share code, notes, and snippets.

/Publisher.java
Created Feb 8, 2018

Embed
What would you like to do?
interface Publisher {
void publish(Message m);
}
class PublisherImpl implements Publisher {
private Map<Topic, Subscriber[]> subscribers;
public Publisher(Map<Topic, Subscriber[]> subscribers) {
this.subscribers = subscribers;
}
public void publish(Message m) {
topic = new Topic(m.getType());
subscribers.getOrDefault(topic, {}).forEach(subscriber -> subscriber.handle(m));
}
}
// use case
publisher = new PublisherImpl(someSubscribers);
publisher.publish(new SomethingCoolHappened());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.