What is Event-Oriented Programming?

Asked

Viewed 14,936 times

38

  • What is event-oriented programming?
  • What Differs between Event-Oriented Programming and Object-Oriented Programming?
  • What languages can we cite that are event-oriented?

2 answers

31


What is event-oriented programming?

It’s when you write code to respond to events.

In event-oriented programming, a routine specializing in monitoring events warns the specific code to respond to a given event that the event it expected occurred; and then the newly notified code responds to the event.

What Differs Event-Oriented Programming and Object-Oriented Programming?

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

The answers to this question are very assertive in 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 an event-oriented code.

What languages can we cite that are event-oriented?

I don’t know any "event-oriented" languages. Strictly speaking, you can program event-oriented programming in any language. Just write an event monitor that warns the code interested in the events it is monitoring.

There are some languages that make event-oriented programming a lot easier: C#, Visual Basic, Delphi.

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

Example of event orientation

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 given button, and you associate this code to the event of clicking 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 on the button; hence the Winforms framework invokes the code that you associated with the click of the button.

  • 1

    I believe that the best language to exemplify POE is Javascript not cited in the answer...

  • 1

    The raven and the desk, gives a book this. A philosopher :D

  • @Wallacemaxters hehehe is from the book Cup in Wonderland.

17

Terminology

The term is usually used event-oriented programming.

In this "paradigm" the execution flow of the code 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 conditional on something occurring earlier.

She works with the hollywood principle where you should call nothing, you must register to be called.

Common uses

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

In many cases events are triggered as events are being verified in a noose, in others there is only an inscription somewhere that must call a part of the code when something occurs.

Relationship with OOP

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

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

EDP does well with imperative programming, functional, etc.

Languages directed to events

I don’t know any language that has this focus and I think only one very specific, maybe one DSL may be. What exists is language that uses this paradigm as a complement. C# is one that clearly has features in the language to handle events. VB.Net is another.

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

Is Javascript event oriented? I may be wrong, but it doesn’t seem to be. O GIFT 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. That’s all.

The paradigm is used in all computing

However you can create event-driven code even if the language does not provide features. The programming done in JS is clearly all directed to events. You can adopt patterns in the language that meet the requirements of the paradigm.

Windows is all about events. Who knows the Win32 API knows that in the background your program is asking Windows if something relevant to that code happened.

  • 2

    +1. I also liked the explanation regarding Javascript. I thought it would be indicated as Event Oriented

  • 2

    In fact, I believe that Javascript is one of the best languages to exemplify POE. Because the ease of creating events is enormous, not just getting stuck in the standard DOM events like click, Hover and etc... See: Creating and Triggering Events.

  • @Kaduamaral but do you realize that it is a library resource and not the language itself? I even believe I am having few votes for it. People don’t understand the separation of everything.

  • From which @bigown library? Sure, you tie the event to an DOM element, but Javascript is not an Ecmascript + DOM fusion?

  • 1

    @Kaduamaral from the standard library, but that’s not the language. Javascript is Ecmascript, period. DOM is another independent thing that is not always available to JS.

  • 2

    @Kaduamaral Events are provided in the specification Ecmascript for client-side computing (section 4.1, Web Scripting), and this is "regulated" (detailed) in the specification of W3C in the form of the code you referenced. So don’t worry, your understanding that Javascript provides event-specific support is correct. If you care about word play, then use the expression "Javascript for computing web client offers great facility for event-oriented programming."

  • Hollywood principle, there’s another one I didn’t know...

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.