What Is event-oriented programming?

  • What is event-driven programming?
  • what differs between event-oriented programming and Object-Oriented Programming?
  • What languages can we cite that are event-oriented?
Author: Caffé, 2015-08-13

2 answers

What is event-driven programming?

Is when you write code to respond to events.

In event-oriented programming, a routine specialized in monitoring events warns the code specialized in responding to a given event that that event it expected occurred; and then the newly warned code responds to the event.

What differs event-oriented programming and Object-Oriented Programming?

These are not paradigms that they can be compared with each other. It would be like describing the differences between a crow and a desk: D

The answers to this question are very assertive about describing object orientation: What are the practical advantages of using object orientation in the day-to-day life of a development team?.

Now notice that you can define objects, their relationships, and their responsibilities, and then make these objects respond to events by programming a event-oriented code.

What languages can we cite that are event-oriented?

I am unaware of "event-oriented" languages. Strictly speaking, you can program event-oriented in any language. Simply write an event monitor that alerts the code interested in the events it is monitoring.

There are some languages that greatly facilitate event-oriented programming: C#, Visual Basic, Delphi.

There are others that do not have any special facilitator, but where you can use design patterns like observable to respond to events - for example Java.

Event orientation example

A common use of event orientation is in programming graphical user interfaces.

See C # WinForms, for example.

In it you write code that will respond for example to a user click on a certain button, and you associate this code with the click event on the button.

Then the WinForms framework monitors the messages that Windows sends to your form, and between these messages Windows warns that the user has clicked the button; hence the WinForms framework invokes the code you associated with the button click.

 29
Author: Caffé, 2020-06-11 14:45:34

Terminology

Usually the term event-driven programming is used.

In this "paradigm" the code execution flow is determined by triggered events, that is, some state changes or some behavior happens and because of this a behavior is called to execute. The execution of the algorithms is conditioned to something that occurred earlier.

She works with the Hollywood Principle where you should not call anything, you should get sign up to be called.

Common uses

Events have their most common use in (G)UIs, but can be used in database, file systems, networks, operating system flags, specific hardware through interrupts, or even commercial and scientific applications can have events on their objects.

In many cases events are triggered as events are being checked in a loop , in others there is only one inscription somewhere one should call a part of the code when something occurs.

Relation to oop

She can work together with OOP and even benefit from it, but they don't necessarily need to. They are orthogonal paradigms and have no relation. Events can be applied to objects, but only this. Any relationship is coincidence. One does not harm the other, on the contrary, just they are more powerful.

In OOP objects communicate through simple methods of passing messages. In EDP this communication occurs through notifications of events.

EDP gets along well with Imperative Programming, functional, etc.

Event-driven languages

I don't know any language that has this focus and I think only a very specific one, maybe a DSL can be. What exist are languages that use this paradigm as a complement. C# is a clear one that has features in the language to address event. VB.Net it's another one.

All languages, one way or another, work with events, even if it does not seem. This is not to say that they are event-driven. Some use this technique a lot, but have nothing specific in the language to treat the events. They have a mechanism that makes it possible for you to create your events and manipulate them. Does this make language event-driven? I do not know, but I think not, otherwise it would be rare language that is not directed to event. Any language that has a mechanism that allows you to treat functions as data in some way can work this way. And there must be even other ways to achieve the same result.

Is JavaScript directed to events? I may be wrong, but apparently not. The DOM and HTML itself looks like it does, but the programming language doesn't seem to have anything specific to handle events. It has a generic mechanism that serves the purpose very well. Only it.

The paradigm is used in all computation

However you can create event-driven code even if the language does not provide features. The programming done in JS is clearly All Event-Driven. You can adopt standards in the language that meet the requirements of the paradigm.

Windows is all event-driven. Anyone who knows the Win32 API knows that deep down your program is asking Windows if something relevant to that code happened.

 16
Author: Maniero, 2020-06-11 14:45:34