IT 317
Event Driven Programming
JOSEPH U.ESPERANZA
Outline
I. What is an event driven system?
II. What is event driven programming?
III. Course Overview
I. What is an event driven system?
• An event is an occurrence of interest
– Events take place at a particular time
• An event driven system is a computer
system where events are a driving force
– Events from the user (mouse click)
– Internal events (variable assignment, timers)
– Events from other computing systems (any
message arriving across the network)
Examples of Event Driven Systems
• Vending Machines
• Cruise Control System in a car
• TV
• Any modern windowing program
– e.g. PowerPoint
What are the events associated with each of
these?
II. Event Driven Programming
• Fundamentally a different paradigm from
procedural (or OOP or functional or logic)
programming
– System is made of objects
– System spends much of its time in stasis
– Events occur that propagate through the
system and then it returns to statis
Basic Event Driven Programming
Model
notifies
Event Source Event Handler
modifies
System Objects
What makes this model unique?
1. Loose Coupling between source and
handler
– Runtime registration
– Multicasting
– Multiplexing
– Separate Compilation
– Inverted Semantics
Runtime registration
document.getElementById("myButton").addEventListener("click", function() {
alert("Button was clicked!");
});
In this example, the addEventListener method registers a click event handler for a
button with the ID myButton during the program’s execution.
Multicasting
public delegate void Notify(); // Delegate In this example,
public class ProcessBusinessLogic
the ProcessCompleted event is multicast to
{ two
public event Notify ProcessCompleted; // Event
handlers: bl_ProcessCompleted1 and bl_Proces
public void StartProcess() sCompleted2.
{
// Some process logic here
OnProcessCompleted();
}
protected virtual void OnProcessCompleted()
{
ProcessCompleted?.Invoke();
}
}
public class Program
{
public static void Main()
{
ProcessBusinessLogic bl = new ProcessBusinessLogic();
bl.ProcessCompleted += bl_ProcessCompleted1;
bl.ProcessCompleted += bl_ProcessCompleted2;
bl.StartProcess();
}
public static void bl_ProcessCompleted1()
{
Console.WriteLine("Process Completed 1");
}
public static void bl_ProcessCompleted2()
{
Console.WriteLine("Process Completed 2");
}
}
Concurrent and Distributed
Processing - continued
• Distributed Processing
– Source and Handler might be on different
computing systems entirely.
– E.g. a web browser makes a request for a
web page from a server.
– Client / Server computing is fairly well
understood. There are many other models,
however.
Course Outline
• Java Event Driven Programming
• Component Based Programming in Java
• Concurrent and Distributed Event
Programming
• Software Engineering Event Driven
Systems