Event oriented programming


Published on

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Event oriented programming

  1. 1. • Events are an important part of Alice programming, allowing the creation of interactive worlds with keyboard and mouse user controls. • Most modern programming languages allow programmers to add events to new software. • Events can be used for many other purposes, such as controlling burglar alarms, checking remote sensors, or checking for system events, like printers running out of paper. • Events are an important part of modern computer programming. 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. Event Driven Programming is a computer programming paradigm. Events are the actions that are performed by the user during the application usage. If a user clicks a mouse button on any object then the click event occurs. If a user moves the mouse then the mouse move event occurs. An event driven programming is a flexible way to allow the programs respond to many different inputs or events. This is a programming in which the primary activity is reaction to the receipt of semantically significant signals. The signals can be from any source, and most commonly including timers, human input, sensors, observation upon shared state, or can be produced during computation when it react with other signals. HOW EVENTS WORKS IN EVENT DRIVEN PROGRAMMING :-> An event occurs whenever an event listener detects an event trigger and responds by running a method called an event handler. Modern operating systems and programming languages contain facilities to let programmers set up event listeners. An event trigger can be almost any activity or condition selected by the programmer, such as a mouse movement, someone pressing the enter key, or a bank account balance changing. EVENT HANDELER :-> An event handler is a method that is activated when the event trigger occurs. Almost any method can serve as an event handler, such as those that play sounds, initiate data communications, or perform calculations. EVENT DRIVEN PROGRAMMING
  2. 2. USE OF EVENT :-> 1. Events can be used to control objects moving in 3D space. 2. Detect when some object moves 3 .Detect when two objects collide 4. Make objects move in response to mouse or keyboard commands. EVENT TRIGGER :-> An event trigger can be almost any activity or condition selected by the programmer, such as a mouse movement, someone pressing the enter key, or a bank account balance changing. FLOW OF PROGRAMME :-> PROGRAMME CAN BE WRITTEN IN FOLLOWING MANNERS :- Public Function Read() As String Dim s As String Dim c As Char() Dim i As Integer;1] 7k;0] GetType (CommControl) m c(read8ufferPosition) For i = 0 To readEufferPosition — 1 c(i) = ChrW(readEuffer(i)) Next readEufferPosition = 0 s = New String(c) End Synctock Return s End Function Private Sub eventThread() Dim r As Integer
  3. 3. PROGRAMMING FLOW IN EVENT DRIVEN PROGRAMMING :-> PROGRAMME IN EVENT DRIEVEN PROAGRAMMING :-> WHAT IS DIFFERNCE BETWEEN OBJECT ORIENTED PROGRAMMING,PROCEDURE ORIENTIED PROGRAMMING AND EVENT DRIVEN PROGRAMMING ? Procedural Programming simply put is dividing your problem into smaller parts (utilizing the Divide and Conqure Law) and then representing each smaller part by a definitive and exact sub-routine/function/procedure. Hence you look at the code as a big pile of different procedures that are coupled with each other, one calling the other, or one calling many while some not calling anything but rather doing specific computations and returning the results. Event Driven?! do not believe there is such a method that stands alone, Event driven is a charactaristic rather than a development approach. Object Oriented Programming (OOP) looks at your problem ad breaks it down to different objects, each object has consists of a number of elements, called Members and Methods. (i.e variables and functions respectively) so your problem is then defined as the different objects working together and inside each other sometimes in a closely coupled manner. the conclusion is, OOP deals with objects and operations on those objects, where as procedural development breaks down computation to little pieces. Event oriented programming cab be written using any language like c++ or c or any programming language .but mainly visiual basic is used to write a programs in event oriented programming .
  4. 4. USES OR APPLICATION OF EVENT ORIENTED PROGRAMMING :-> Event-driven programs are typically used in graphical user interfaces (GUI) and multi-tasking/multi-threaded environments. The operating system maintains a message queue containing events generated by all active applications and services. Every message has an ID denoting the target application, along with the ID of the event itself plus any data that is relevant to the event. When an application is idle, it enters an idle loop which repeatedly checks the first message on the queue. If the application ID matches, the message is dequeued and processed. If the ID does not match, the idle loop terminates. Since ever application is given an allocated time-slice of the CPU according to its priority, so long as the applications are idle during their allotted time then all messages will be processed fairly rapidly. However, if an application is busy and the first message in the queue is intended for it, that message will effectively block all other messages to all other applications. The operating system will appear sluggish because messages are being enqueued all the time but the busy application is preventing them from being processed. To prevent this programmers must periodically yield control to the system during an intensive process to allow messages to be enqueued, and then enter idle mode to process any pending messages. Once it has dealt with those messages it can continue the intensive process until the next yield point.Since events can be posted from one application to another, applications must be prepared to deal with them. For instance, if the user chooses to shut down the system, every application will be notified that it must close. But if the application is running an intensive operation then it will not be possible to close the application until that process has been aborted gracefully. There are various ways of dealing with this but generally the application will override the idle loop in order to filter messages. That is, the override will dequeue messages but will not process them unless certain conditions are satisfied. This is known as "eating" events. If the event is an instruction to close the application but a process is still running, then the idle loop will store the event and set an abort flag that the process can check at each yield point, allowing it to terminate gracefully. When the idle loop determines there is no running process but the abort flag has been set, it will reset the abort flag and repost the event it stored which can then be dealt with normally Most modern computer programs that people use have Graphical User Interfaces (GUIs). A GUI has icons on the computer screen and a mouse (or other device) to control a pointer that can be used to operate the computer.
  5. 5. Modern GUIs like the Word 2007 interface require the use of event-driven programming. ADVANTAGE :-> - It allows for more interactive programs. Almost all modern GUI programs use event driven programming. - It can be implemented using hardware interrupts, which will reduce the power used by the computer. - It allows sensors and other hardware to easily interact with software. DISADVANTAGE :-> - For simple programs, event driven programming is often more complex and cumbersome than batch programming. - The flow of the program is usually less logical and obvious. CONCLUSION :-> There are many uses along with pros and cons when it comes to Event Driven Programming. One Advantage is flexibility; in fact you could say that event driven programming is one of the most ‘flexible programming language types.’ One of the main reasons being why it’s flexible is its allowance to let the user design the program in sections. In other words the programmer is given the main control over the program in terms of they instruct the program to do and also the time in which they what this to happen. ‘Suitability of the graphical interface’‘Simplicity of Programming’‘Ease of Development’ REFERENCE :-> http://en.wikipedia.org/wiki/Event-driven_programming- 2.http://wiki.tcl.tk/1772-- 3.http://searchcloudapplications.techtarget.com/definition/ event-driven-application--- 4.http://eventdrivenpgm.sourceforge.net/