C# Event Processing Model

Slides:



Advertisements
Similar presentations
Data Structures: A Pseudocode Approach with C 1 Chapter 5 Contd... Objectives Explain the design, use, and operation of a linear list Implement a linear.
Advertisements

Exception Handling Chapter 15 2 What You Will Learn Use try, throw, catch to watch for indicate exceptions handle How to process exceptions and failures.
CS  C++ Function Pointers  C# Method References  Groundwork for Lambda Functions.
Georgia Institute of Technology Workshop for CS-AP Teachers Chapter 3 Advanced Object-Oriented Concepts.
CIS162AD Inheritance 09_inheritance.ppt. CIS162AD2 Overview of Topics  Inheritance  Virtual Methods used for Overriding  Constructors & Inheritance.
What is the Chain? It’s a behavioral design pattern. It deals with how objects make requests and how they are handled.
Interfaces. In this class, we will cover: What an interface is Why you would use an interface Creating an interface Using an interface Cloning an object.
Object-Oriented Analysis and Design
Programming Paradigms Imperative programming Functional programming Logic programming Event-driven programming Object-oriented programming A programming.
C# Event Processing Model Solving The Mystery. Agenda Introduction C# Event Processing Macro View Required Components Role of Each Component How To Create.
Object Oriented Software Development
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Understanding Events and Exceptions Lesson 3. Objective Domain Matrix Skills/ConceptsMTA Exam Objectives Understand events and event handling Understand.
Slides Credit Umair Javed LUMS Web Application Development.
Delegates and lambda functions Jim Warren, COMPSCI 280 S Enterprise Software Development.
Using Intents to Broadcast Events Intents Can be used to broadcast messages anonymously Between components via the sendBroadcast method As a result Broadcast.
Programming Languages and Paradigms Object-Oriented Programming (Part II)
CIS 3301 C# Lesson 13 Interfaces. CIS 3302 Objectives Understand the Purpose of Interfaces. Define an Interface. Use an Interface. Implement Interface.
Lecture Set 11 Creating and Using Classes Part B – Class Features – Constructors, Methods, Fields, Properties, Shared Data.
CCA Event Specification Proposal
1 Chapter Eleven Handling Events. 2 Objectives Learn about delegates How to create composed delegates How to handle events How to use the built-in EventHandler.
Delegates and Events Callback Functionality and Event-Driven Programming Svetlin Nakov Technical Trainer Software University
ECE122 Feb. 22, Any question on Vehicle sample code?
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Object Oriented Programming.  Interface  Event Handling.
Module 8: Delegates and Events. Overview Delegates Multicast Delegates Events When to Use Delegates, Events, and Interfaces.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 27 JavaBeans and.
Chapter 5 Introduction to Defining Classes
QT Programming QT Programming Ruku Roychowdhury. Background QT is a cross platform application framework. Widely used to develop GUI applications. Originally.
ASP.NET User Controls. User Controls In addition to using Web server controls in your ASP.NET Web pages, you can create your own custom, reusable controls.
Introduction to Object-Oriented Programming Lesson 2.
From C++ to C# Part 5. Enums Similar to C++ Similar to C++ Read up section 1.10 of Spec. Read up section 1.10 of Spec.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 32 JavaBeans and Bean.
Events Programming in C# Events CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis.
Lecture10 Exception Handling Jaeki Song. Introduction Categories of errors –Compilation error The rules of language have not been followed –Runtime error.
Arrays & Enum & Events. Arrays Arrays are data structures consisting of related data items of the same type. Arrays are fixed-length entities—they remain.
 ASP.NET provides an event based programming model that simplifies web programming  All GUI applications are incomplete without enabling actions  These.
Introduction to Exceptions in Java CS201, SW Development Methods.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Chapter 32 JavaBeans and Bean Events
Memory Management.
Events and Event Handling
Java Exceptions a quick review….
INF230 Basics in C# Programming
Where are we ? Setup Sprites Input Collision Drawing Sprites
Delegates and Events Svetlin Nakov Telerik Corporation
Java Programming Language
Delegates and Events 14: Delegates and Events
Methods Attributes Method Modifiers ‘static’
Leftover Patterns Chain of Responsibility
Chapter 3: Using Methods, Classes, and Objects
Chapter Eleven Handling Events.
6 Delegate and Lambda Expressions
Learning Objectives Classes Constructors Principles of OOP
Delegates & Events 1.
#in-class Take a look at A3 assignment description Respond to the poll on #in-class Post questions you have about A3 on #in-class, or emoji a question.
Lesson 7. Events, Delegates, Generics.
Event Driven Systems and Modeling
CSE 143 Java Exceptions 1/18/2019.
Exception Handling and Event Handling
Constructors, GUI’s(Using Swing) and ActionListner
Java Exceptions Dan Fleck CS211.
Interfaces.
Java Programming Language
DELEGATES AND EVENT MODELING
Creating and Using Classes
Events, Delegates, and Lambdas
Presentation transcript:

C# Event Processing Model 1

C# Event Processing Macro View Generally speaking, two logical components are required to implement the event processing model: 1) An event producer (or publisher) 2) An event consumer (or subscriber) Each logical component has assigned responsibilities Consider the following diagram

C# Event Processing Macro View When an Event occurs notification is sent to all the subscribers on the list for that particular event… Object B processes the event notification in its event handler code Object A (Event Publisher) Object B (Event Subscriber) Object B subscribes to event (or events) generated by Object A. Subscriber List (Object B) Event Handler Code Object A maintains a list of subscribers for each publishable event

C# Event Processing Macro View This diagram hides a lot of details How is the subscriber list maintained? How is the event generated? How is the notification sent to each subscriber? What is an event – really? How can you add custom event processing to your applications?

Required Components To implement custom event processing in your programs you need to understand how to create the following component types: Delegates Event Generating Objects (publishers) Events Event Notification Methods Event Handling Objects (subscribers) Event Handler Methods

Required Components You will also need to know how to pass information related to the event between the event generating object and the subscriber object The EventArgs class can be used as-is or subclassed The EventArgs class captures generic information about an object and the event that occurred

Role Of Each Component Delegate Example Delegate types represent references to methods with a particular parameter list and return type Example void EventHandler(Object sender, EventArgs e) Represents a method that has two parameters, the first one being of type Object and the second being of type EventArgs. Its return type is void Any method, so long as its signature matches that expected by the delegate, can be handled by the delegate

Role Of Each Component Delegate A delegate is a reference type object. A delegate extends either the System.Delegate or MulticastDelegate class Depends on whether one (Delegate) or more (MulticaseDelegate) subscribers are involved You do not extend Delegate or MulticastDelegate The C# compiler does it for you

Role Of Each Component Delegate The delegate object contains the subscriber list It is actually implemented as a linked list where each node of the list contains a pointer to a subscriber’s event handler method Delegates are types – like classes Except – you declare them with the delegate keyword and specify the types of methods they can reference

Role Of Each Component Publisher A publisher is any class that can fire an event and send event notifications to interested subscribers A publisher class contains the following critical elements: An event field This is what subscribers subscribe to… An event notification method This activates the subscriber notification process when the event occurs And some means of generating the event or recognizing the event in question has occurred This usually happens in a method as well

Role Of Each Component Event An event is a field in a class Events are declared with the event keyword Events must be a delegate type Delegates, remember, are objects that contain a list of pointers to subscriber methods that delegate can process An event field will be null until the first subscriber subscribes to that event

Role Of Each Component Event Notification Method In addition to an event field a publisher will have a method whose job it is to start the subscriber notification process when the event in question occurs An event notification method is just a normal method It usually has a parameter of EventArgs or a user-defined subtype of EventArgs. But it can have any number and type of parameters you require

Role Of Each Component Subscriber A subscriber is a class that registers its interest in a publisher’s events A subscriber class contains one or more event handler methods

Role Of Each Component Event Handler Method An event handler methods is an ordinary method that is registered with a publisher’s event The event handler method’s signature must match the signature required by the publisher’s event delegate

?

References