Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is an EventListener an Observable?

I am currently following a class about Design Patterns and was wondering whether an EventListener is an Observable?

I don't really see a difference between them because both have a list of subscribers and notify these subscribers when something has changed.

like image 387
Daan Avatar asked May 09 '11 19:05

Daan


People also ask

Is listener the same as observer?

"A listener is essentially waiting for an event to occur on a given object, which is what an observer does" not exactly, according to the DP book observers don't wait for any kind of event, but a change in the state of the subject, which then the observer can query for (pull).

What is an EventListener?

An event listener is a procedure or function in a computer program that waits for an event to occur. Examples of an event are the user clicking or moving the mouse, pressing a key on the keyboard, disk I/O, network activity, or an internal timer or interrupt.

How does an EventListener work?

Often an event listener is registered with the object that generates the event. When the event occurs, the object iterates through all listeners registered with it informing them of the event.

What is observable design pattern?

What Is the Observer Pattern? Observer is a behavioral design pattern. It specifies communication between objects: observable and observers. An observable is an object which notifies observers about the changes in its state. For example, a news agency can notify channels when it receives news.


1 Answers

An Observable is simply an object where you can observe it's actions. So anything where you can listen to an action and then be told that action occurs is an Observable.

This means an Event Listener is one. Because you can listen to events and the events immediately notify you that they have happened.

Personally when anyone says Observable I think events. This is my cookie cutter example of what observables are. A similar example would be a publish-subscribe system which is just events under a different name (it does have subtly different use case).

like image 169
Raynos Avatar answered Sep 21 '22 20:09

Raynos