Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 505
mohsen kamrani Avatar asked Feb 28 '14 17:02

mohsen kamrani


1 Answers

  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.

like image 138
Lightman Avatar answered Sep 28 '22 02:09

Lightman