SlideShare une entreprise Scribd logo
1  sur  6
Interface
•Interface is similar to abstract class. They used as template and can not instantiate the object. The
interface can be inherited.
•Interface provide another way to implement polymorphism.
•Through interfaces, we specify methods that a component must implement without actually
specifying how the method is implemented. We just specify the methods in an interface and leave it to
the class to implement those methods .
• VB.net does not support the multiple inheritance directly but using interface we can achieve multiple
inheritance.
•Use the Interface keyword to create an interface and implements keyword to implement the
interface.
•Once you create an interface you need to implement all the methods specified in that interface.
• It is a collection of prototypes. It contains methods, properties, events. They can not contain static
functions or constructors.
•Syntax:
Public Interface Name_of_interface
function declarations
End Interface
Example:
Public Interface vehicle
Sub driveBike()
Sub driveCar()
End Interface
Public Class Pune : Implements vehicle
Public Sub driveBike() Implements vehicle.driveBike
Console.Writeline(“I m driving Bike in Pune”)
End Sub
Public Sub driveCar() Implements vehicle.driveCar
Console.Writeline(“I m driving Car in Pune”)
End Sub
End Class
Public Class Mumbai: Implements vehicle
Public Sub driveBike() Implements vehicle.driveBike
Console.Writeline(“I m driving Bike in Mumbai”)
End Sub
Public Sub driveCar() Implements vehicle.driveCar
Console.Writeline(“I m driving Car in Mumbai”)
End Sub
End Class
Sub Main()
Dim M As New Mumbai()
Dim P As New Pune()
P.driveBike()
P.driveCar()
P.driveBike()
P.driveCar()
End Sub
Delegates
A function pointer is a special type of variable that is used to access a function
using its address. To support function pointers, the .NET Framework provides
the concept of delegates. A delegate is not a real function. It provides a syntax
for a function that it would be associated with.
Delegates are pointers that are used to store and transfer information like the
memory address, event handled by functions and subroutines. Delegates are
type safe, since they check for the signatures of functions and subroutines
only if same, they transfer information. A delegate is declared using the
keyword Delegate to a function or procedure name.
Creating a Delegate:
[modifier] Delegate Sub/Function Name (parameter(s)) As ReturnType
The modifier factor can be Public, Private, or Friend. This is followed by either the Delegate
Sub or the Delegate Function expression.
A delegate must have a name: The Name factor of this formula. The name follows the rules we
have been observing for valid names of the Visual Basic language.
Because a delegate is some type of a template for a procedure, you must use parentheses. If this
procedure will not take any argument, you can leave the parentheses empty.
If the delegate will be associated with a sub-procedure, there is no return type. Here is an
example:
Module Exercise
Delegate Sub Messenger()
End Module
Module Module1
Public Delegates Sub Firstdelegate (ByVal x As integer, ByVal y As Integer)
Public Sub Add(ByVal x As integer, ByVal y As Integer)
Console.Writeline(“Addition is”, x+y)
End Sub
Public Sub Mul(ByVal x As integer, ByVal y As Integer)
Console.Writeline(“Multiplication is”, x*y)
End Sub
Sub Main()
Dim Del, Del1 As Firstdelegate ‘object of delegate
Del=AddressOf Add ‘Assign Address of function
Del1=AddressOf Mul
Del.Invoke(10,20) ‘ used to invoke or call the function
Del1.Invoke(5,3)
End Sub
Delegates are of two types:
Single-cast delegates:
* If a delegate invokes a single method, then it is called as a Single cast delegate.
* Single-cast Delegates refer to a single method with matching signature.
They are derived from the System.Delegate class
Multi-cast delegates:
*They are nothing but a single delegate that can invoke multiple methods of matching
signature.
*Derives from System.MulticastDelegate class which is a subclass of System.Delegate
*In this, we create a single delegate that in turn invokes multiple encapsulated methods.
We can use Multi-cast Delegates when multiple calls to different methods are required.

Contenu connexe

Tendances

Abstract class in c++
Abstract class in c++Abstract class in c++
Abstract class in c++Sujan Mia
 
Delegates and events
Delegates and eventsDelegates and events
Delegates and eventsIblesoft
 
Java interfaces
Java interfacesJava interfaces
Java interfacesjehan1987
 
Lambda Expressions in C# From Beginner To Expert - Jaliya Udagedara
Lambda Expressions in C# From Beginner To Expert - Jaliya UdagedaraLambda Expressions in C# From Beginner To Expert - Jaliya Udagedara
Lambda Expressions in C# From Beginner To Expert - Jaliya UdagedaraJaliya Udagedara
 
Evolution of C# delegates
Evolution of C# delegatesEvolution of C# delegates
Evolution of C# delegatesmbaric
 
Functional programming
Functional programmingFunctional programming
Functional programmingKibru Demeke
 
8 abstract classes and interfaces
8   abstract classes and interfaces 8   abstract classes and interfaces
8 abstract classes and interfaces Tuan Ngo
 
This keyword and final keyword
This keyword and final  keywordThis keyword and final  keyword
This keyword and final keywordkinjalbirare
 
Day02 01 Advance Feature in C# DH TDT
Day02 01 Advance Feature in C# DH TDTDay02 01 Advance Feature in C# DH TDT
Day02 01 Advance Feature in C# DH TDTNguyen Patrick
 
Doppl development iteration #2
Doppl development   iteration #2Doppl development   iteration #2
Doppl development iteration #2Diego Perini
 
Java interfaces & abstract classes
Java interfaces & abstract classesJava interfaces & abstract classes
Java interfaces & abstract classesShreyans Pathak
 

Tendances (20)

C# Delegates
C# DelegatesC# Delegates
C# Delegates
 
Java interface
Java interfaceJava interface
Java interface
 
Delegates in C#
Delegates in C#Delegates in C#
Delegates in C#
 
Interfaces
InterfacesInterfaces
Interfaces
 
Abstract class in c++
Abstract class in c++Abstract class in c++
Abstract class in c++
 
Delegates and events
Delegates and eventsDelegates and events
Delegates and events
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Delegates and events
Delegates and events   Delegates and events
Delegates and events
 
Lambda Expressions in C# From Beginner To Expert - Jaliya Udagedara
Lambda Expressions in C# From Beginner To Expert - Jaliya UdagedaraLambda Expressions in C# From Beginner To Expert - Jaliya Udagedara
Lambda Expressions in C# From Beginner To Expert - Jaliya Udagedara
 
Inheritance
InheritanceInheritance
Inheritance
 
Evolution of C# delegates
Evolution of C# delegatesEvolution of C# delegates
Evolution of C# delegates
 
javainterface
javainterfacejavainterface
javainterface
 
Functional programming
Functional programmingFunctional programming
Functional programming
 
8 abstract classes and interfaces
8   abstract classes and interfaces 8   abstract classes and interfaces
8 abstract classes and interfaces
 
This keyword and final keyword
This keyword and final  keywordThis keyword and final  keyword
This keyword and final keyword
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
Day02 01 Advance Feature in C# DH TDT
Day02 01 Advance Feature in C# DH TDTDay02 01 Advance Feature in C# DH TDT
Day02 01 Advance Feature in C# DH TDT
 
Doppl development iteration #2
Doppl development   iteration #2Doppl development   iteration #2
Doppl development iteration #2
 
Java interfaces & abstract classes
Java interfaces & abstract classesJava interfaces & abstract classes
Java interfaces & abstract classes
 

En vedette (12)

Dpsd lecture-notes
Dpsd lecture-notesDpsd lecture-notes
Dpsd lecture-notes
 
Fuzzy logic
Fuzzy logicFuzzy logic
Fuzzy logic
 
Unit 4
Unit 4Unit 4
Unit 4
 
Hdlc
HdlcHdlc
Hdlc
 
Unit 3
Unit  3Unit  3
Unit 3
 
Shift register
Shift registerShift register
Shift register
 
B sc cs i bo-de u-iii counters & registers
B sc cs i bo-de u-iii counters & registersB sc cs i bo-de u-iii counters & registers
B sc cs i bo-de u-iii counters & registers
 
14827 shift registers
14827 shift registers14827 shift registers
14827 shift registers
 
Shift Registers
Shift RegistersShift Registers
Shift Registers
 
Cultural Impact on Digital Design
Cultural Impact on Digital DesignCultural Impact on Digital Design
Cultural Impact on Digital Design
 
Counters In Digital Logic Design
Counters In Digital Logic DesignCounters In Digital Logic Design
Counters In Digital Logic Design
 
Chapter 5 counter
Chapter 5 counterChapter 5 counter
Chapter 5 counter
 

Similaire à Interface

Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++ppd1961
 
Structural pattern 3
Structural pattern 3Structural pattern 3
Structural pattern 3Naga Muruga
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1YOGESH SINGH
 
Unit iii vb_study_materials
Unit iii vb_study_materialsUnit iii vb_study_materials
Unit iii vb_study_materialsgayaramesh
 
Mastering Python lesson 4_functions_parameters_arguments
Mastering Python lesson 4_functions_parameters_argumentsMastering Python lesson 4_functions_parameters_arguments
Mastering Python lesson 4_functions_parameters_argumentsRuth Marvin
 
C++ Object oriented concepts & programming
C++ Object oriented concepts & programmingC++ Object oriented concepts & programming
C++ Object oriented concepts & programmingnirajmandaliya
 
21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)ssuser7f90ae
 
Evolution of Patterns
Evolution of PatternsEvolution of Patterns
Evolution of PatternsChris Eargle
 
Object oriented concepts & programming (2620003)
Object oriented concepts & programming (2620003)Object oriented concepts & programming (2620003)
Object oriented concepts & programming (2620003)nirajmandaliya
 

Similaire à Interface (20)

Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Vb.net iv
Vb.net ivVb.net iv
Vb.net iv
 
DS Unit 6.ppt
DS Unit 6.pptDS Unit 6.ppt
DS Unit 6.ppt
 
.NET F# Events
.NET F# Events.NET F# Events
.NET F# Events
 
Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++
 
cp Module4(1)
cp Module4(1)cp Module4(1)
cp Module4(1)
 
Structural pattern 3
Structural pattern 3Structural pattern 3
Structural pattern 3
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1
 
Unit iii vb_study_materials
Unit iii vb_study_materialsUnit iii vb_study_materials
Unit iii vb_study_materials
 
Mastering Python lesson 4_functions_parameters_arguments
Mastering Python lesson 4_functions_parameters_argumentsMastering Python lesson 4_functions_parameters_arguments
Mastering Python lesson 4_functions_parameters_arguments
 
C++ Object oriented concepts & programming
C++ Object oriented concepts & programmingC++ Object oriented concepts & programming
C++ Object oriented concepts & programming
 
21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Functions
FunctionsFunctions
Functions
 
Evolution of Patterns
Evolution of PatternsEvolution of Patterns
Evolution of Patterns
 
Object oriented concepts & programming (2620003)
Object oriented concepts & programming (2620003)Object oriented concepts & programming (2620003)
Object oriented concepts & programming (2620003)
 
Poo java
Poo javaPoo java
Poo java
 
Poo java
Poo javaPoo java
Poo java
 
Poo java
Poo javaPoo java
Poo java
 
Poo java
Poo javaPoo java
Poo java
 

Dernier

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 

Dernier (20)

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 

Interface

  • 1. Interface •Interface is similar to abstract class. They used as template and can not instantiate the object. The interface can be inherited. •Interface provide another way to implement polymorphism. •Through interfaces, we specify methods that a component must implement without actually specifying how the method is implemented. We just specify the methods in an interface and leave it to the class to implement those methods . • VB.net does not support the multiple inheritance directly but using interface we can achieve multiple inheritance. •Use the Interface keyword to create an interface and implements keyword to implement the interface. •Once you create an interface you need to implement all the methods specified in that interface. • It is a collection of prototypes. It contains methods, properties, events. They can not contain static functions or constructors. •Syntax: Public Interface Name_of_interface function declarations End Interface
  • 2. Example: Public Interface vehicle Sub driveBike() Sub driveCar() End Interface Public Class Pune : Implements vehicle Public Sub driveBike() Implements vehicle.driveBike Console.Writeline(“I m driving Bike in Pune”) End Sub Public Sub driveCar() Implements vehicle.driveCar Console.Writeline(“I m driving Car in Pune”) End Sub End Class Public Class Mumbai: Implements vehicle Public Sub driveBike() Implements vehicle.driveBike Console.Writeline(“I m driving Bike in Mumbai”) End Sub Public Sub driveCar() Implements vehicle.driveCar Console.Writeline(“I m driving Car in Mumbai”) End Sub End Class Sub Main() Dim M As New Mumbai() Dim P As New Pune() P.driveBike() P.driveCar() P.driveBike() P.driveCar() End Sub
  • 3. Delegates A function pointer is a special type of variable that is used to access a function using its address. To support function pointers, the .NET Framework provides the concept of delegates. A delegate is not a real function. It provides a syntax for a function that it would be associated with. Delegates are pointers that are used to store and transfer information like the memory address, event handled by functions and subroutines. Delegates are type safe, since they check for the signatures of functions and subroutines only if same, they transfer information. A delegate is declared using the keyword Delegate to a function or procedure name.
  • 4. Creating a Delegate: [modifier] Delegate Sub/Function Name (parameter(s)) As ReturnType The modifier factor can be Public, Private, or Friend. This is followed by either the Delegate Sub or the Delegate Function expression. A delegate must have a name: The Name factor of this formula. The name follows the rules we have been observing for valid names of the Visual Basic language. Because a delegate is some type of a template for a procedure, you must use parentheses. If this procedure will not take any argument, you can leave the parentheses empty. If the delegate will be associated with a sub-procedure, there is no return type. Here is an example: Module Exercise Delegate Sub Messenger() End Module
  • 5. Module Module1 Public Delegates Sub Firstdelegate (ByVal x As integer, ByVal y As Integer) Public Sub Add(ByVal x As integer, ByVal y As Integer) Console.Writeline(“Addition is”, x+y) End Sub Public Sub Mul(ByVal x As integer, ByVal y As Integer) Console.Writeline(“Multiplication is”, x*y) End Sub Sub Main() Dim Del, Del1 As Firstdelegate ‘object of delegate Del=AddressOf Add ‘Assign Address of function Del1=AddressOf Mul Del.Invoke(10,20) ‘ used to invoke or call the function Del1.Invoke(5,3) End Sub
  • 6. Delegates are of two types: Single-cast delegates: * If a delegate invokes a single method, then it is called as a Single cast delegate. * Single-cast Delegates refer to a single method with matching signature. They are derived from the System.Delegate class Multi-cast delegates: *They are nothing but a single delegate that can invoke multiple methods of matching signature. *Derives from System.MulticastDelegate class which is a subclass of System.Delegate *In this, we create a single delegate that in turn invokes multiple encapsulated methods. We can use Multi-cast Delegates when multiple calls to different methods are required.