Download An object-oriented library for event-driven design

Transcript
4
THE POWER OF ABSTRACTION, REUSE AND SIMPLICITY
3 EVENT-DRIVEN DESIGN
Event-driven design offers interesting architectural solutions when execution
must respond to events whose order is hard to predict in the program text.
Putting the user in control
GUI and WUI (Web User Interfaces) provide the most immediately visible
illustration of why an event-driven scheme may be useful.
Consider this piece of WUI built with ASP.NET (the Web programming
library for .NET):
The interface that we show to our user includes a text field and a button. There
might be many more such “controls” (the Windows term for graphical
elements, called “widgets” in the X Window system). We expect that the user
will perform some input action, and we want to process it appropriately in our
program. The action might be typing characters into the text field, clicking the
button, or any other, such as menu selection, using controls not shown above.
But which of these will happen first? Indeed, will any happen at all?
We don’t know.
In the early days, the problem didn’t exist. Programs would just read user
input, using for example a loop to consume successive lines, as in
from
read_line
count := 0
until
last_line empty
loop
count := count + 1
-- Store last_line at position count in Result:
Result put (last_line, count)
read_line
end
.
.
[A]