Chapter 5. Demystifying Inheritance in VB.NET
In This Chapter
✓ | Demystifying inheritance |
✓ | Creating derived classes |
✓ | Using protected access |
✓ | Understanding polymorphism |
Inheritance is typically thought of as an advanced feature of object-oriented programming, as if it were something you shouldn’t confront until your third year of grad school. Nonsense! Inheritance is actually a pretty simple idea, and one that you must deal with even in the simplest of ASP.NET applications.
In this chapter, you come to grips with the basics of inheritance. You get the lowdown on how ASP.NET takes advantage of inheritance for every Web page you create — and on how you can use inheritance in your own classes. After you finish this chapter, you may want to glance over Book 4, Chapter 6, to get a taste of some of the other things you can do with inheritance.
Understanding Inheritance
The very first line of a typical VB.NET code-behind file looks something like this:
Partial Class _Default Inherits System.Web.UI.Page
Okay, it’s fairly obvious what the Partial
keyword means — that only part of the class is defined by this source file. The rest of the class is defined elsewhere. (In the case of an ASP.NET code-behind file, the rest of the class is defined by a source file that’s generated automatically by ASP.NET from the .aspx
file for the page.)
But what about the Inherits
keyword? It says that this class is based on — or derives from — another class. In this case, that other class is System.Web.UI.Page
.
The System.Web.UI.Page ...
Get ASP.NET 2.0 All-In-One Desk Reference For Dummies® now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.