Chapter 5. Inheritance and Exceptions in VB.NET

Team-Fly    

 
Application Development Using Visual Basic and .NET
By Robert J. Oberg, Peter Thorsteinson, Dana L. Wyatt
Table of Contents
Part 2.  VB.NET Language


Visual Basic has long supported the notion of class and an object-based programming model. VB.NET brings to Visual Basic the concept of inheritance , which has long been considered one of the cornerstones of object-oriented programming. Visual Basic has also provided an exception handling mechanism through the OnError construct. VB.NET provides structured exception handling , which is a more robust exception handling mechanism that is shared among all the .NET languages.

In this chapter we study in detail these important features of VB.NET. First we review the fundamentals of object-oriented programming. Next, the Acme Travel Agency case study is introduced. This case study is developed throughout the entire book as we explain more about .NET. We consider some abstractions that will enable us to implement a reservation system for a variety of resources, and we provide an implementation of a hotel reservation system. The abstract base classes we define provide reusable code that enables us to easily implement other kinds of reservation systems. The key is finding the right abstractions.

We will see how VB.NET language features facilitate object-oriented programming. Certain details of VB.NET, such as use of access control ( Public , Private , and Protected ) and properties can help express abstractions in a way that is safe and easy to use. We will then look at other object-oriented features of VB.NET, such as Overridable [1] methods , method hiding, and polymorphism. A problem in languages supporting inheritance is the fragile base class problem, [2] and we will see how VB.NET helps in avoiding this pitfall.

[1] The VB.NET keyword Overridable makes a method virtual, which means that it is dynamically dispatched at runtime rather than being bound at compile time. Virtual methods support one of the pillars of object-oriented programming, known as polymorphism.

[2] The fragile base class problem refers to breaking binary compatibility with existing client programs when a new version of a component with different class members is deployed. This is explained in greater detail later in this chapter.

We discuss exception handling in VB.NET in some detail, including the use of user -defined exception classes (which rely on inheritance) and structured exception handling.

This chapter is very much driven by our case study. We introduce object-oriented features of VB.NET as we elaborate the case study. At the end of the chapter we cover additional concepts not illustrated by the case study.


Team-Fly    
Top
 


Application Development Using Visual BasicR and .NET
Application Development Using Visual BasicR and .NET
ISBN: N/A
EAN: N/A
Year: 2002
Pages: 190

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net