Skip to content

Instantly share code, notes, and snippets.

@yfklon

yfklon/Main.java

Created Jun 5, 2019
Embed
What would you like to do?
public class Main {
public static void main(String[] args) {
PubSubService pubSubService = new PubSubService();
IPublisher musicPublisher = new Publisher(pubSubService, "music");
IPublisher newsPublisher = new Publisher(pubSubService, "news");
ISubscriber musicSubscriber = new Subscriber(pubSubService);
ISubscriber anotherMusicSubscriber = new Subscriber(pubSubService);
ISubscriber newsSubscriber = new Subscriber(pubSubService);
musicSubscriber.subscribe("music");
anotherMusicSubscriber.subscribe("music");
newsSubscriber.subscribe("news");
musicPublisher.publish("New album is coming.");
musicPublisher.publish("New concert!");
newsPublisher.publish("Brexit bla bla.");
pubSubService.broadcast();
System.out.println("Messages of music subscribers; ");
musicSubscriber.printMessages();
anotherMusicSubscriber.printMessages();
System.out.println("Messages of news subscribers; ");
newsSubscriber.printMessages();
}
}
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.