Event Driven Programming- Lecture 2
Event Driven Programming- Lecture 2
Lecture 2
Object Oriented Programming
Class
Application
Class Class
Class Class
Class
Presentation Layer
Data Layer
Object
- An instance of a class
Car
Car1
Make
Model Car2
Color
Start() Car3
Drive()
Stop()
Syntax
public class ClassName
// class members
}
Syntax
public class ClassName
{
public datatype FieldName;
public returntype MethodName()
{
// method body
}
}
Demo: Create a Customer Class
Static Members of a Class
public ClassName()
}
Demo: Create a Customer Constructor
Constructor Overloading
Public VS Private
Can a constructor be private?
C# Properties (Get and Set)
- More on getters and setters
C# Property
A property is like a combination of a variable and a method, and it has two methods: a get and a set
method.
class ClassName
{
private string field;
public string Field
{
get { return field; } // get method
set { field = value; } // set method
}
}
C# Property
class ClassName
}
Generics
NotificationService
Events
SomeOtherService
Customer
NotificationService
Publisher/ Emitter
Subscriber / Receiver
How to
1- Define a delegate
2- Define an event
3- Raise the event
NotificationService