Node.js: Function vs EventEmitter

No… interfaces are a bit different. They govern how two systems, entities, classes or unit of code can interact with one another. Now an interface could describe that a system has events that you can subscribe to. Back to the dance party analogy, lets say that MC tells the group that he also takes requests for songs, but you have to meet him at the MC desk and fill out a small form. This would be the MC setting out what he can do (take requests) and how you do that (by sending him some data via a form). As you fill out his form, he might also say "Hey, I also mention when songs are about to be played. You can subscribe to this event so when I announce the song (emit) you will know and can get out on the dance floor.

The keyword you will often see with interfaces is the word “contract”. A governed predetermined set of rules that both systems/classes or whatever agree to. The MC agrees to playing songs by request and you agree that you will fill out the form as requested to use that feature.

1 Like