Objective
In the Observer pattern some objects (subscribers) register to be notified when another one (the emitter) publishes an event. The emitter does not know who they are or what they do: it only walks its list.
Instructions
- The first line has the number
nof commands. Each one issubscribe name event,unsubscribe name eventoremit event data(the data may have several words). - When emitting, notify the subscribers of that event in the order they subscribed, showing
name receives event: datafor each one; if nobody listens, showNobody listens to event. Subscribing twice to the same event does not duplicate the notice.
4
subscribe ana news
subscribe bob news
emit news hola
emit sport gol
ana receives news: hola
bob receives news: hola
Nobody listens to sport
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise