0% found this document useful (0 votes)
4 views

01_Intro_to_EDP

The document outlines a module on event-driven programming, emphasizing practical applications in high-level development environments and introducing concepts like multiprocessor support and parallel event transformation. It covers various programming paradigms, including imperative, declarative, functional, object-oriented, and event-driven programming, detailing their principles and applications. Assessments, contact hours, and project requirements are also specified, highlighting the importance of understanding course content for successful completion.

Uploaded by

miriamoamohammed
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

01_Intro_to_EDP

The document outlines a module on event-driven programming, emphasizing practical applications in high-level development environments and introducing concepts like multiprocessor support and parallel event transformation. It covers various programming paradigms, including imperative, declarative, functional, object-oriented, and event-driven programming, detailing their principles and applications. Assessments, contact hours, and project requirements are also specified, highlighting the importance of understanding course content for successful completion.

Uploaded by

miriamoamohammed
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 24

Week1

Event-Driven Programming

Dr. Abdul Razzaq


[email protected]
Module Aims
 Aims:
 This module will provide students with a comprehensive introduction to
event-driven programming where a strong emphasis will be placed on
practical application in at least two high-level development environments.
In addition, students will be introduced to multiprocessor support for
event-driven programs and shown how to improve event
processing performance through parallel event transformation .
 Learning Outcomes
 Describe event-driven programming and create event handlers.
 Create GUI-based applications to solve a variety of problems.
 Utilise graphical GUI development tools to develop event-driven, GUI-
based applications.
 Understand the concepts of parallel programming and demonstrate
this understanding through programming.
 Show how to improve event processing performance through parallel
event transformation.
2
Agenda

 Programming Paradigms
 Event-driven Programming and its Principles
 From 1 to 12 O’clock
 Assessments and Gradings
Computer Programming?
Computer programming is the process of performing a
particular computation usually by designing and building
an executable computer program.

The purpose of programming is to find a sequence of instructions that will


automate the performance of a task (which can be as complex as
an operating system) on a computer, often for solving a given problem.

The source code of a program is written in one or more languages that are
intelligible to programmers, rather than machine code, which is directly
executed by the central processing unit.
Programming Types and Paradigms
 Classifying programming languages based
on the way code is written, organized and
executed

 Several common programming paradigms


or styles of programming exist, specifically:
 • Imperative; • Declarative; • Object-
oriented; • Functional; • Interactive;
and • Event-driven

 Although a small number of languages


support only a single programming
paradigm, most languages allow multiple
paradigms to be used.

5
Declarative Programming

In a general sense, code written in the declarative programming style instructs the computer
as to what should be done, instead of telling the computer how to do it. It specifies the end
result and lets the language engine decide how it should be done.

This is achieved through a domain-specific language (DSL) allowing the user to express what
it is they want. Such languages free the user from having to employ lower-level constructs
such as assignments and loops that would otherwise be needed to achieve the desired goal.
Declarative Programming

SQL is an example of such a domain-specific language. As you can


see in each of the four basic statements below, it is the end goal of
the operation that is specified, not the steps by which that goal
should be achieved.

SELECT SomeColumn FROM SomeTable WHERE AnotherColumn I S NOT NULL;


INSERT INTO SomeTable(SomeColumn) VALUES(SomeValue);
UPDATE SomeTable SET SomeColumn = SomeValue WHERE AnotherColumn
< 20;
DELETE FROM SomeTable WHERE SomeColumn >= 1000;
Imperative Programming

An imperative style is one in which the program code explicitly


instruct the computer as to how to achieve the desired results using statements that impact on
the program’s state.

Languages that facilitate the imperative paradigm will:


• Allow the programmer to state the order in which computation takes place; and
• Allow computation operations to modify the state of the program.

C, Java, Python, and R are examples of languages that facilitate the imperative
programming paradigm.
Imperative (Sequential) Programming

Imperative programming example in Python

number1 = 10
number2 = 15
total = number1 + number2

Each statement in this code modifies the state of the program. The first two statements
create (change the state of) variables by assigning values to them. The final line adds these
values and assigns them to a new variable, again changing the state of the program.
Functional Programming
In the functional programming paradigm, programs are created by evaluating functions. Functional programming
is based on several concepts:
• Immutability - In pure functional programming, data structures are immutable, i.e. their state can not be
changed.
• First Class (Higher-order in math) Functions - functions are treated like other variables.
• Pure Functions, functions that produce no side effects, either by changing the state of memory or any I/O
device. This is known as referential transparency.
• Recursion, where functions can invoke themselves to accomplish the same result as looping in imperative
languages. This can require using a stack.
Functional Programming

Functional programming example in Java


public int factorial(int n){
i f ( n == 0)
return 1;
else
return n * factorial( n - 1 );
}
factorial(10)

In this very simple example, we define a function to calculate the


factorial of a number. This function features recursion, in that the
function calls itself. The function is then called with the number we want
to find the factorial of as an argument. No variables are used. The state
of the program does not change.
Object Oriented Programming

Object-Oriented Programming (OOP) is based on the idea of combining data and


the code that operates on it. It is based on several principles:

• Encapsulation is the combining of data structures and code


(methods) that work on the data within a single, closely coupled unit, known as a class. It is
also known as information hiding, as the data structures and inner workings of an object
are inaccessible unless access is provided through public methods.
• Inheritance allows classes to inherit data and behaviors from other classes, permitting the
re-use of data structures and methods.
• Abstraction, the process of identifying common features of objects and features, so that
they can be combined into a parent class.
• Polymorphism, the ability to handle differently, depending on their class
Event-driven Programming
 Event-driven programming is a
paradigm in software design
where the flow of the program is
determined by events.
 Such as user actions (mouse
clicks, keyboard presses),
sensor outputs, or message
passing from other programs.

13
A Comparison
Other Paradigms Event-driven Paradigm
Programmer Sets the Order of Action Computer User Determines the Order of
Actions
Programmer Controls the Program’s Flow of Control is Determined at Runtime
Flow
Programmer-written Functions are called Programs are Interactive
by programmers

The event-driven programming paradigm is


popular in developing GUI applications, server-side
(web) applications, and in systems programming,
particularly where performance and
responsiveness are critical.
14
Multi Paradigm Programming
Just to Meet Different Needs
Many programming languages allow programming in one or more paradigms.
For instance, with Java, you can employ imperative, object-oriented, functional
programming, and event-driven styles.
Languages purposely designed to allow programming in more than one
paradigm are called multi-paradigm languages.
Software Architecture Example

16
Event

 Something that happens


 Any system that uses GUI-based user interaction is event-based
(Windows)
 Mouse Click
 Key Press
 System Clock Timer

 Can be caused by computer or user


 Can occur differently each time the program is executed

 Mobile phones (Android) have a multitude of events

17
Principles of Event-driven Programming
 Event Listener: The event listener listens for events and
dispatches them to the appropriate handlers.
 This loop runs continuously throughout the life of the
program.
 Event Handlers: Blocks of code designed to respond to
specific events.
 When an event occurs, the corresponding handler is executed
 Asynchronous Behavior: Unlike traditional linear and
sequential programming, event-driven programs often
operate asynchronously.
 The program waits for events to occur and responds to them as they
happen.
 Loose Coupling: Loosely coupled components. They
operate independently and only communicate through
18
events.
Principles of Event-driven Programming (Cont.)
 Callback Functions: A function is passed as an argument
to another function and is executed on an event detection.
 Concurrency: Event-driven architectures support concurrent
operations.
 In environments where events occur independently and at
unpredictable times.
 State Management: Managing the state of an application
can be more complex in event-driven programming
 Due to the asynchronous and unpredictable nature of events.
 Scalability: Highly scalable
 Particularly in distributed systems where events can be
produced and consumed across different systems and
networks.
 Flexibility and Scalability: More flexible and scalable
19
 New event types and handlers can be added without altering
12 O'clock: Assessment 2
Project Presentation/Interview 2
Soft Labs

1 O'clock: Intro
11 O'clock: Assessment 1 Hard Labs
Introduction & Principles
Project Presentation/Interview 1
Paradigms
Assessment Week

10 O'clock: GUI-3 2 O'clock: Soft Events


JavaFX with Multithreading, Exception Handling, generating,
Thread Confinement in JavaFX Throwing

9 O'clock: Concurrency 3 O'clock:Network Apps


Concurrent Programming, Client/Server Apps, Socket
Synchronization Programming, TCP/UDP Apps

8 O'clock: Parallelism
Performance focused Multi- 4 O'clock: GUI-1
threading, Fork-Join Principle EDM, MVC, JavaFX GUI 1

7 O'clock: Multiprocessor
Support 5 O'clock: GUI-2
Multithreading in Java, Threads JavaFX GUI 2, Event Handling
States and Communication using Lambda Expressions

6 O'clock: MidTerm
Project
20
Assessments (More on Brightspace)

 Attendance – 20%
 Attendance in the first half hour – counting at the end of the
lecture
 Labs – 20%
 The lab coordinator will assess you based on the output of your
code (after execution) for a Randomly Selected Task. He/she may
ask one random question. Half + Half
 Labs will always be assessed in the next week of lab available
 Midterm (30%):
 Project – 30%
 Final (30%):
 Project – 30%
21
Projects
 Projects (Individual Assessment + Two Members Group):
 Midterm Project – Description and Assessment Criteria will be made available in
Week2 – Hard Deadline Week 6 (Before Labs)
 Final Project – Description and Assessment Criteria will be made available in
Week5 – Hard Deadline Week 11 (Before Labs)
 You should view this assignment as a means to create a relevant portfolio that you might
present to a future employer, so you MUST utilize GitHub ( https://github.com/) to save
and record your progress.
 Presentations and Interviews (Week 11 and Week 12):
 You will be required to submit a video presentation of a walk through your code
and how it works covering the assessment criteria you addressed (max 7 min)
 The main purpose of the interview is twofold
 To assess your comprehension of the work you have submitted and related course content
 To provide an opportunity for you to receive timely face-to-face feedback on your work and
progress during the semester.
 N.B. No matter how good your project work is if you fail to demonstrate a sufficient
understanding of the project and related course content you can receive 0 marks
 Interview Scheduling based on student ID (earliest in a group will be considered)

22
Contact Hours
 Contact hours:
 2 hours in class lecture
 2 hours of labs Friday (Labs will start from Week 2)

 Thursday 09:00 - 10:00 LEC, Room -> B1023 (sometimes, to be announced)


Thursday 13:00 - 14:00 LEC, Room -> ERB001 (sometimes, to be announced)

Monday 09:00 - 11:00 LAB CS2044 – 2C (I have a note for 2C students)


Tuesday 09:00 - 11:00 LAB CS2044 – 2A
Tuesday 16:00 - 18:00 LAB CS2044 – 2B

 Note: Week 9 is Easter Break week – no classes


 Note for 2C Students
 Friday 12:00 – 13:00 – CS-2044

23
Grades Breakdown

 30% D2
35% D1
40% C3
48% C2
52% C1
56% B3
60% B2
64% B1
72% A2
80% A1

24

You might also like