🎧 New: AI-Generated Podcasts Turn your study notes into engaging audio conversations. Learn more

M1_Lesson-2.pdf

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Transcript

LESSON 2: What is Event Driven Programming? Event driven programming is the programming paradigm in the field of computer science. In this type of programming paradigm, flow of execution is determined by the events like user clicks or other programming threads or query result from database....

LESSON 2: What is Event Driven Programming? Event driven programming is the programming paradigm in the field of computer science. In this type of programming paradigm, flow of execution is determined by the events like user clicks or other programming threads or query result from database. Events are handled by event handlers or event callbacks. Event-driven programming is currently the default paradigm in software engineering. As the name suggests, it uses events as the basis for developing the software. These events can be something the users are doing — clicking on a specific button, picking an option from drop-down, typing text into a field, giving voice commands, or uploading a video — or system-generated events such as a program loading. Event-driven programming is applied extensively in graphical user interfaces and applications that perform certain actions in response to user input (for example, JavaScript web applications). For software teams, developing an event- driven application inevitably adds complexity to system design and delivery. Principles of Event-Driven Programming A set of functions that handle events. Depending on the implementation these can be blocking or non-blocking. A mechanism for binding the registered functions to events. The main loop which constantly polls for new events and calls the matching event handler(s) when a registered event is received. Features of Event Driven Programs: Service oriented Service oriented is a programming paradigm that is used to write programs that are made for services. Time driven Time driven in event driven programming is a paradigm, it is code that runs on a time trigger, this could be a piece of code that runs at a specific time, which could be once a week or whenever a program is launched, this means it is a pre- set task. Event Handlers Event handler is a function or method that takes place when a certain event happens, they are executed in response to a certain event that takes place, for example this could be on a button, when a button is clicked the code is ran, if the button is clicked again after that it will run again, this is an event handler. Trigger functions: Trigger functions decide what code is ran when a specific event occurs, they are used to choose when event handlers are ran for the event that occurs, most applications have a trigger function for each event that is likely to occur. Events(Mouse, keyboard and user interface): 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 may different ways, it can be with the 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. Pre-defined functions: A pre-defined function is a function that is built into the programming language. C# provides some pre-defined methods such as Main () 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. A local variable, in C#, is a type of variable declared by local variable declaration at the beginning of a block the variable is intended to be local to. A local variable is a type of variable that can be used where the scope and extent of the variable is within the method or statement block in which it is declared. Global variables: A global variable is a variable that can be used in every part of a program, java doesn’t use global variables as it can make a program harder to control and can make it harder to manage variables. A global variable is a variable accessible anywhere, for example a field "counter" type integer. The global variable can be accessed from any function or class within the namespace. Parameter passing: Parameter passing is used by a function, it allows a value to be passed through a program, it can be used for many things, including an alarm or finding a certain character at a certain position, though on an alarm, the event doesn’t take place until a certain time has come, this is due to events. Parameter passing in C# Parameters are means of passing values to a method. There are four different ways of passing parameters to a method in C# which are as: 1. Value 2. Ref (reference) 3. Out (reference) 4. Params (parameter arrays) Passing parameter by value By default, parameters are passed by value. In this method a duplicate copy is made and sent to the called function. There are two copies of the variables. So if the value was changed in the called method it won't be changed in the calling method. Passing parameter by ref Passing parameters by ref uses the address of the actual parameters to the formal parameters. It requires ref keyword in front of variables to identify in both actual and formal parameters. Passing parameter by out Like reference parameters, output parameters don't create a new storage location and are passed by reference. It requires out keyword in front of variables to identify in both actual and formal parameters. Passing parameter by param (parameter arrays) Params parameters "params" parameter is a very useful feature in C#. It is used when we don't know the number of parameters will be passed to the called method. Param can accept multiple values or "params" should be a single dimensional or a jagged array. The params keyword specify a method parameter that takes an argument where the number of arguments is variable. No additional parameters are permitted after the params keyword in a method declaration, and only one params keyword is permitted in a method declaration. The difference between ref and out parameter modifiers. ref out ref is a mechanism of Out is also a mechanism of parameter passing by reference parameter passing by reference A variable to be sent as ref A variable to be sent as out parameter must be initialized. parameter don't need to be initialized ref is bidirectional i.e. we have Out is a unidirectional i.e. we to supply value to the formal don't supply any value but we parameters and we get back get back processed value. processed value. Modularity: Modularity is modules that have been spread out into different parts of a program to carry out tasks one after the other, each module works separate and independently from the others. When a program is modular, it doesn’t need every different part to actually function, and things can be deleted without getting loads of errors, this is because everything works independently. Modularity can also be used to breakdown a large program into separate entities, this can make a big complicated system more straight forward and easy to understand, though it can increase the time it takes to develop the program. A module is a construct representing a unit of code (set of types, values, functions and any expression allowed by a language) and satisfying: Interface: A module may publicly provide and require a set of components. Encapsulation: A module may hide or make abstract some of its components. Sets of modules are meant to be connected according to the dependencies induced by their interfaces: Independence: A module should depend only on the interfaces of its dependencies. Procedures: Procedures are small programs that are known as sub-programs, procedures can be used to avoid repetition when creating a program. Procedures are a set of tasks, that can be carried out in an order, they can be used to carry out certain actions. Programming libraries: There are many different programming libraries, they contain pre-compiled routines, this can be source code, data files, script, templates, fonts or code form. 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 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. Examples of Languages that use event driven programming: Visual basic, Java or C#

Tags

event-driven programming software engineering computer science
Use Quizgecko on...
Browser
Browser