What is the relation of 'Event Driven' and 'Object Oriented' programming?

mok picture mok · Feb 28, 2014 · Viewed 29.7k times · Source

These days, I hear almost everywhere about 'event driven' programming.

Wikipedia says:

In computer programming, event-driven programming is a programming paradigm in which the flow of the program is determined by events such as user actions (mouse clicks, key presses), sensor outputs, or messages from other programs/threads. Event-driven programming is the dominant paradigm used in graphical user interfaces and other applications (e.g. Javascript web applications) that are centered around performing certain actions in response to user input.

Isn't this exactly our old friend OOP? And if this is not OOP what is the difference?

Answer

Lightman picture Lightman · Jan 25, 2015
  1. Object Oriented Programming (OOP) and Event-Driven Programming (EDP) are orthogonal, which means that they can be used together.

  2. In OOP with EDP all OOP principles (encapsulation, inheritance and polymorphism) stay intact.

  3. In OOP with EDP objects acquire some mechanism of publishing event notifications and subscribing to event notifications from other objects.

  4. The difference between OOP with / without EDP is control flow between objects.

    • In OOP without EDP control moves from one object to another object on a method call. Object mainly invokes methods of other objects.

    • In OOP with EDP control moves from one object to another object on event notification. Object subscribes on notifications from other objects, then waits for notifications from the objects it is subscribed on, does some work based on notification and publishes it's own notifications.

  5. Conclusion: OOP+EDP is "exactly our old friend OOP" with control flow inverted thanks to Event-Driven Design.