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

Event-Driven Programming (Autosaved)

Event-driven programming is a paradigm based on handling events that occur during program execution. Events are controlled by event handlers, trigger functions, and event loops. When an event occurs, the corresponding event handler is called to respond. The event loop continuously checks for pending events and dispatches them to the proper handlers. This allows programs to remain responsive to user input and other events.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views

Event-Driven Programming (Autosaved)

Event-driven programming is a paradigm based on handling events that occur during program execution. Events are controlled by event handlers, trigger functions, and event loops. When an event occurs, the corresponding event handler is called to respond. The event loop continuously checks for pending events and dispatches them to the proper handlers. This allows programs to remain responsive to user input and other events.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 28

Event-Driven

Programming
Event-Driven Programming

- is a programming paradigm that is based on the


events that happen during the execution of a program.
These events are controlled by Event Handlers,
Trigger Functions and Event Loops.
In Event Driven models the programs are not
procedural any longer. One of the main features of
Event Driven Programming is that it creates a user-
friendly environment, because when the user takes an
action, this action triggers a chain of events which
cause the program to do what the user wants within the
program.
Key Concepts of Event-Driven Programming
1. Events - events represent specific occurrences or interactions within a program.
These events can originate from various sources, such as user input, system
notifications, hardware sensors, or messages from other parts of the program. Three
of the most common events include:
• User Interface Events – these are events generated by user interactions with a
graphical user interface (GUI), like clicking a button, pressing a key, or resizing
a window.
• System Events – these events are related to the system's state or operations,
such as a timer reaching a specific time, a file being modified, or a network
socket receiving data.
• Custom Events – programmers can define custom events to represent specific
actions or triggers within their applications. For example, a game might have
custom events for player actions like jumping or shooting.
Cntd.
Key Concepts of Event-Driven Programming
2. Event Handlers - are functions or blocks of code that are associated with specific
events. When an event occurs, the corresponding event handler is called or executed
to respond to the event. Event handlers are registered or attached to specific events,
specifying which code should run when those events occur.
3. Event Loop - the event loop is a central part of an event-driven program. It
continuously checks for pending events in a queue and dispatches them to their
respective event handlers. The event loop ensures that events are processed in the
order they occur and that the program remains responsive to user interactions and
other events.
4. Asynchronous Programming - event-driven programming often involves
asynchronous operations, which means that the program can continue executing
other tasks while waiting for events or asynchronous tasks to complete.
Asynchronous programming is crucial for building responsive applications.
Cntd.
Integrated Development Environment (IDE)
IDE is a programming environment or a software application used by computer
programmers to code or create applications. It provides comprehensive facilities to
computer programmers for software development.

The main purpose of IDE is to maximize programmer/developer productivity


and build software efficiently. It increases developer productivity by combining
capabilities such as software editing, building, testing, and packaging in an easy-to-use
application. Just as writers use text editors and accountants use spreadsheets, software
developers use IDEs to make their job easier.
Cntd.
There are various components of IDE in which some are specific to a particular IDE
while some are common to all; means general components.
General Components of an IDE
1. Source Code Editor – is a text editor program designed specifically for editing source code of
software applications or computer programs.
2. Compiler – translates the source code to machine readable code that can be executed by the
computer.
3. Linker – is a computer program that takes one or more object files generated by a compiler
and combines them into a single executable file. A program used to provide links to the
libraries needed for an executable program.
4. Interpreter – is a computer program that is used to directly execute program instructions.
5. Debugger – is a computer program used to test and debug the programs. The main use of a
debugger is to run the target program under controlled conditions that permits the programmer
to track its operations in progress and monitor changes in computer resources that may
indicate malfunctioning code. Its primary purpose is to help programmers to identify and fix
bugs (errors) in their code.
6. GUI Builder – this lets the programmer develop a graphical user interface by dragging and
dropping icons from a toolbar onto the interface window and editing them with graphics tools.
Cntd.
Integrated Development Environment (IDE)
The .NET Framework

A framework is a structured and pre-designed set


of code libraries, tools, and conventions that provides a
foundation for building applications. It is a structure
you can build software and application on. Frameworks
are typically associated with a specific programming
language.
Cntd.
Components of .NET Framework
Cntd.
Common Language Runtime (CLR)
Common Language Runtime is an interoperable runtime
environment from the .NET Framework which provides an environment to
run all .NET programs. CLR helps in converting the source code to native
code; it is a two-step process where the source code is first converted to a
Microsoft Intermediate Language (MSIL) and then CLR uses Just-In-Time
(JIT) compilers to convert MSIL code to native code.

• Microsoft Intermediate Language (MSIL) is platform-neutral, human-


readable representation of code. It contains instructions and metadata that
describe the program’s logic and structure.

• Just-In-Time compiler is a style of compilation that translates the MSIL


into native machine code that is specific to the platform.
Cntd.
Common Language Runtime (CLR)
C#

C# Compiler

Microsoft Intermediate Language (MSIL)

Common Language Runtime


JIT (Just-In-Time) Compilers

NATIVE CODE
Cntd.
Base Class Library (BCL)
Base Class Library encapsulates a large number of common
functions which can be used by the developers. It is the core component of
the .NET Framework, which provides a set of classes, types, and namespaces
that form the foundation for building .NET applications.

• Namespace – is a container for organizing and categorizing related


classes, types, and other program elements.
• Class – is a fundamental object-oriented programming concept that
represents a blueprint or template for creating objects. It defines the
properties and methods (functions) that objects of that class will have.
• Types – are used to define and represent data structures, objects, and
values in .NET Applications.
Cntd.
Common Language Specification (CLS)
Common Language Specification specifies a set of rules that needs
to be adhered or satisfied by all language compilers targeting CLR. CLS is
nothing but guidelines that language to follow so that it can communicate
with other .NET languages in a seamless manner.
Understanding Classes,
Inheritance, and Namespaces
Classes

A class is a reference type that encapsulates data


(such as constants and fields) and defines its behaviors
using programming constructs such as methods,
properties, constructors, and events.
A class represents an abstract idea that you would
like to include in an application. For example, the .NET
Framework includes a Form class, which includes data
fields for storing information such as the size of the form,
the form’s location, the form’s background color, title bar
text, and so on. The Form class also contains methods that
define how a form behaves, such as a Show() method that
shows the form onscreen and an Activate() method that
activates the form by giving it the focus.
A class functions as the blueprint of a concept.
When you want to work with a class in a program, you
create instances of the class, which are called objects.
Objects are created from the blueprint defined by the class,
but they physically exist in the sense that they have memory
locations allocated to them and they respond to messages.
For example, to create an actual form in a program, you
create an instance of the Form class. After you have that
instance available, you can actually work on it—you can set
its properties and call methods on it.
Each object maintains its own copy of the data
that is defined by the class. This allows different
instances of a class to have different data values.
For example, if you have two instances of the
class Human— objYou and objMe—these two objects
can each have a different value for their EyeColor
properties. You access the member of an object by
using ObjectName.MemberName syntax, where
ObjectName is name of the class instance and
MemberName can be a field, a property, a method, or
an event. When an object is created, it creates its
members in a special area in memory called the heap,
and it stores a pointer to that memory. Because classes
use pointers to refer to their data, so that they are also
called reference types.
Static Members of a Class
– A class can have static members (fields,
methods, and so on). Static members belong to the class
itself rather than to a particular instance. A static class
cannot inherit from other classes. No instance of a class
is required in order to access its static members. When
you access a static member of a class, you do so by
prefixing its name with the name of the class — for
example, ClassName.StaticMemberName.
Access Modifiers
– A class can define the accessibility of its member by
including an access modifier in its declaration. C# has four
different access modifiers:

• public — Allows the member to be globally accessible.


• private — Limits the member’s access to only the containing
type.
• protected — Limits the member’s access to the containing
type and all classes derived from the containing type.
• internal — Limits the member’s access to within the current
project.
Inheritance

Object-oriented programming languages such as


C# provide a feature called inheritance. Inheritance
allows you to create new types that are based on types
that already exist. The original type is called a base
class, and the inherited class is called a derived class.
When one class inherits from another class, the
derived class gets all the functionality of the base class. The
derived class can also choose to extend the base class by
introducing new data and behavioral elements. In
developing Windows forms, you will frequently inherit
from the Form class to create your own custom forms; these
custom forms will be at least as functional as an object of
the Form class, even if you do not write any new code in
the derived class. Value types such as structs cannot be used
for inheritance.
Namespace
The .NET Framework provides a feature called a
namespace that allows you to organize classes
hierarchically in logical groups based on what they do
and where they originate. Not only does a namespace
organize classes, but it also helps avoid naming
conflicts between vendors because each classname is
required to be unique only within its namespace. A
general convention is to create a namespace like this:

CompanyName.ApplicationName
A class is therefore identified, for example, as
QueCertifications.Exam1.ExamQuestions, where
QueCertifications is the unique name for a company,
Exam1 is a unique application within that company, and
ExamQuestions is the name of a specific class.
QueCertifications could have another class with the
same name, ExamQuestions, as long as it belongs to a
different application, such as QueCertifications.Exam2.
The objective of namespaces is to keep the complete
naming hierarchy unique so that there are no naming
conflicts.
A namespace is a string in which dots help create
a hierarchy. In the namespace
QueCertifications.Exam1, Exam1 is called a child
namespace of QueCertifications. You could organize
classes at two levels here: at the level of
QueCertifications and also at the level of Exam1. You
can create a hierarchy with as many levels as you want.
A System namespace in the FCL acts as the root
namespace for all the fundamental and base classes
defined inside the FCL. One of the fundamental classes
defined in the System namespace is Object class
(uniquely identified as System.Object). This class acts
as the ultimate base class for all other types in the .NET
Framework.
The System.Windows.Forms namespace
organizes classes for working with Windows forms.
The System.Drawing namespace organizes classes for
creating graphical elements.

You might also like