This unit aims to enable learners to develop the skills and understanding required to design and develop event
driven applications.
Event driven programming is a very flexible way of allowing programs to respond to many inputs or events.
Unlike traditional programming, where the control flow is determined by the program structure, the control
flow of event driven programs is largely driven by external events. Typically, event loops are pre-programmed
to continually look for information to process.
This unit allows learners to become familiar with the underpinning concepts of event driven programming
and subsequently to develop particular skills in an event driven language. The unit starts by looking at the
features of event driven programming, explores the tools and techniques used in their development and takes
learners through design and program development. Learners will use a structured approach to the design
and development of applications, ensuring the solution is well documented and tested thoroughly against the
original user requirement.
Event handling features in many languages including Visual Basic, Visual Basic for Applications and many other
systems.
On completion of this unit a learner should:
Service orientated: - is a term used to describe the concept of multiple services (processes written in different programming languages) advertised and
accessed as and when needed by an organisation.
Service oriented is a programming paradigm that is used to write programs that are made for services. If something is requested, the action is carried
out, if a user wanted to minimize an application that they are using, they would click on the – icon in the top right of the page and the application
will minimize into the task bar, this is service orientated.
Time driven: -
is the term used to describe processing which occurs when tasks are regulated by a clock, i.e. actions are occurring at set intervals and typically
need a real-time response. In this case, an event could be generated by a ‘timer’ trigger.
Such as cooking a meal with a microwave or can be carried out at certain increments repeatedly such as with traffic lights that change automatically
after a certain amount of time.
In addition there are a number of other terms which are used when discussing event driven programming.
Time driven programming is often used in real time, where code execution is controlled by the computer clock.
A program is divided into a set of tasks that need to be regularly activated. The activation pattern us stored into a dispatch table, where rules are
used to schedule the tasks.
Event handlers: - are the actual program code modules which are executed when a particular trigger has occurred. For example, if a user clicked a
button this would trigger an event handler for the code actions associated with the button.
VB.Net uses subroutines for event handling, with the name of the object followed by the name of the event – see below:
Trigger functions: - are used by event loops to identify and launch a response to an event which has happened in an event loop.
This is what decides what causes the event to take place, for example making the button single click will cause it to run when it is clicked,
setting it to double click will make it require 2 clicks for it to run. Every object has a range of trigger functions that can be used to run
the event, upwards of 50 or more on some.
These are used along with the object’s name to determine with event handler to run
Every object has a range of trigger functions, one for each possible event that can happen to it. For example, txtText could have an event
handler for the following triggers: GotFocus, TextChanged etc...
Temporal triggers mean triggers set off by duration of time
State triggers are when the current situation causes a certain set of procedures to run
What is the trigger here??
5 min's
The programmer chooses which event(s) to respond to by selecting the appropriate trigger function.
Different controls have different events (events for a text box not the same for a button)
Events (eg mouse, keyboard, HTML object, form, user interface) : - A form is a visual container used to group together user interface components such as text boxes, buttons, labels, checkboxes etc. It is used to provide an input mechanism for a user that is both approachable and functional.
For the events within a program to happen, they need to be triggered, this is when the user interacts with an object, which may be a button getting clicked by a mouse, events can be triggered in many different ways, it can be with your mouse, due to movement, left clicking, right clicking or scrolling, the keyboard can also be used to set off events, this can be from pressing certain keys, holding down certain keys or from something being typed into the keyboard. The events happen due to code being assigned to something, for example code might be assigned to a button, so when that button is clicked the code is executed.
For example when playing a game with a controller pressing the trigger will cause the gun to fire while moving the stick will cause the character to move. The same trigger can do different events depending on the situation, for example clicking on an icon will do something different to clicking on a button.
Every object has a range of trigger functions – one for each possible event
A Button has a Click event, a GotFocus event, a MouseHover event etc
Pre-defined functions: - A pre-defined function is a function that is built into the programming language, for example system.out.println is used in java, this is a pre-defined function,
You can use this as procedural so this code will run as soon as the program is started, or you can assign the code to a button, so that it can triggered through an event. Local variables: - A local variable is a variable that is declared within a method, that variable will only be used by the method where it is mentioned, other methods will not use it. An example of a local variable in the code below is age,
Event loops: - are processing cycles which continually look for events to happen (e.g. a button click, file deletion or arrival of a data packet over a network).
An example of this is when the screen goes to sleep but moving the mouse will get it back again, this is because the event loops are checking for events like this and are running all the time in the background.
Event Driven Programs have event loops built into the environment. The loops keep testing the interface to detect whether anything has happened, such as clicking on a button or typing into a textbox etc.
Event Loops are also known as event listeners
Programmers not normally aware of these
The Event loop keeps testing the user interface to see if anything has happened (e.g. clicking on a button or pressing a key)
When detected, the event is passed to the trigger function which then finds the appropriate event handler to run the code written for this purpose
Other (non user) activities can also cause an event to trigger – typically used in networking and when reading from or writing to files
Flexibility: -
This is what allows the program to have massive variability and enable it to be different to everybody else’s, there is lots of options for the design so it can be whatever the programmer envisioned it to be. They can also decide how they want to write the code and make it work the way the want it to.
Programmers have enormous control over where to place code and how to start it.
Every object has a good choice of events that a program can respond to. These events give an excellent level of control over exactly what the program will respond to when the user does something
Service Oriented
A lot of networked applications use service oriented techniques so that different applications can reuse code components.
Service oriented applications separate the service implementation from the program interface that uses the service.
An example is a request from a database.
XML (Extensible Markup Language) is commonly used for interfacing with such service oriented architectures
Suitability for graphical interfaces: -
Event driven programs are very suitable for graphical user interfaces (GUIs) as they are an excellent match for each other. A GUI presents
the user with a wide variety of graphical choices and menus that can be used with the mouse or keyboard (or other input devices), usually
with no set sequence that the user must follow.
An event driven programming language will use this GUI approach to give the user a variety of controls. Each control reacts to events with code
that is just right for each event and for how the program is expected to be used.
Most controls are quite independent from each other, so the code will be modularised into event handlers.
Event driven programming for simplicity of programming and ease of development:
Event driven programming can be a lot easier and simple to use and to program as it is very visual, when creating things such as buttons
you can simply just select it, place it onto a form and then just add code to the button so it has some use to the program, this makes it
easier to use and more simple as you don’t need to write the code to create things like buttons, you just need to add code to them, this
can also save a lot of time, makes programming simple and can make the development process easier. Pre-written code can also be used, you
can also select commands from drop down lists, which shows commands that can be used, and this makes developing a program faster, simple and easier.
Event-driven languages such as C#, VB.NET and Visual C++ allow a programmer to build up their program gradually with simple building blocks.
Event Programmers can add and code one object at a time, using simple constructs
Pre-written code and drop-down lists showing choice of possible commands
Errors are highlighted and step through debugging
Code modules can be re-used or imported from libraries, built-in wizards can be used
Online and local help files are readily available
Disadvantages
Errors can be more difficult to spot than with simpler, procedural programs
Programs with complex GUIs may be slower to load and run than simpler programs – particularly if RAM is insufficient
Programs with too many forms can be very confusing and/or frustrating for the user
Using the Activity Sheet, create a simple Calculator, you should ensure that you pay close attention to the table provided in the instructions as this
will provide you with the naming conventions that should be used when creating a program in VB.Net.
EXTENTION
Using your now created calculator create buttons for the missing aritmatic operators.Using
EXTENTION
Now you have a simple calculator lets try and make it scientific
STRETCH & CHALLENGE
Now lets try an reproduce the calculator that is available in windows
The information covered in this page covers the knowledge and understanding linked to the criterion in the table below.
Links to Assessment Criteria | Description |
---|---|
LO1 | Key features: service oriented; time driven; event handlers; trigger functions; events eg mouse, keyboard, HTML object, form, user interface; event loops; flexibility; suitability for graphical interfaces; simplicity of programming; ease of development |
Functional Skills English | Reading, Writing, Comprhension, Problems Solving, Nouns |
Functional Skills Maths | Compression,Reduction |
British Values | None covered in this session. |
Equality and Diversity |
Links to Learning Outcomes |
Links to Assessment criteria |
|
---|---|---|