Advanced VB.NET Programming – Delegates



Advanced VB.NET Programming – Delegates

Advanced VB.NET Programming – Delegates

In this computer science lesson, you will learn about delegates, otherwise known as type safe function pointers. A delegate is also known as a callback. Delegates can make it easier to introduce new functionality to an application, as you will see here. A good understanding of delegates is also beneficial when developing multithreaded applications and applications that include custom event handling.

You will learn what a delegate is and how to use a delegate in Visual Basic.NET. You will learn how to define a delegate object which refers to a function with parameters, how to create an instance of a delegate and how to invoke the function referred to by the delegate.

You will also learn why you might want to use a delegate. The benefits and drawbacks of programming with delegates are discussed with reference to some key design principles of object oriented programming, namely, the single responsibility principle and the open-closed principle (OCP).
To get the most out of this lesson, it will help if you are familiar with coding classes with methods and properties in VB.NET. You can find the essentials of object oriented programming with VB.NET in a separate series of videos.

Chapters:
00:00 Introduction
00:33 What is a delegate?
00:58 A simple object oriented scenario
04:24 The problem
06:02 Define the delegated functions
07:24 Define a delegate with function parameters
08:58 Define a method with a delegate parameter
10:29 Create an instance of a delegate
10:55 Call a method with a delegate
11:46 Using properties of a class
13:55 Delegate for a sub procedure
14:34 A more realistic design approach
15:58 The pros and cons of using delegates

Comments are closed.