Library tutorials & articles

New Object-Oriented Capabilities in VB.NET

Summary

Visual Inheritance

So far we’ve been discussing the new OO features of the VB.NET language, with a large focus on inheritance.

However, VB.NET also supports visual inheritance for Windows Forms. This means that we can create a Windows Forms form, and then inherit from that form to create other forms that have the same layout, controls, and behaviors. This topic was covered in more detail in Chapter 4.

We can also use inheritance to create our own versions of Windows Forms controls. For instance, we may want to create an enhanced TextBox control that performs some specialized validation of the input data. This can be accomplished through inheritance by creating a subclass of the original TextBox control class and enhancing it as needed. This was also covered in Chapter 4.

The same is true of Web Forms controls, where we can take an existing Web Forms control and create a subclass. Our subclass can override existing functionality or add new functionality as required. See Chapter 6 for more on this.

Summary

Of all the features requested for the new version of VB, perhaps the most common was true inheritance. As we’ve seen in this chapter, not only does VB.NET provide us with inheritance, but we also gain a number of other important new features and enhancements.

VB.NET dramatically enhances the way we create and work with multiple interfaces, making them far easier to use than in the past. Additionally, through the support for events as being a formal part of an interface, we can now express all the elements of an interface through this mechanism – methods, properties, and events.

For most people, the elimination of reference counting in favor of a garbage collection scheme for object termination will be a non-issue. However, it is important to be aware of this change, since an object that maintains a reference to expensive system resources will need some mechanism other than its termination to release those valuable resources.

Overall, VB.NET dramatically enhances our ability to create OO applications with VB, while preserving the vast majority of the features we have become used to in previous versions of the language.

Comments

  1. 12 May 2005 at 01:06

    application level

  2. 04 Nov 2004 at 12:10

    Quote:
    [1]Posted by bsol on 19 Mar 2004 04:06 PM[/1]
    Error in the article "New Object-Oriented Capabilities in VB.NET - Events"


    Derived classes cannot raise base class events in VB.Net. Handle them sure, but not raise them - even if they are declared public. In order to achieve this handle the base class event and raise a derived class event instead.


    B.



    While it is true that VB.NET cannot directly raise events in base classes from a derived class, there is an easy workaround. BTW, in C# you can simply call an event in a base class like: base.onMyEventName(EventArgs e).


    But in VB.NET you cannot use MyBase.EventName() at all. But the workaround is an easy one.
    1) In the base class add an overridable sub that simply raises an event defined in the base class.



    Public MustInherit Class MyClass


     Protected Event MyEventName(ByVal e as EventArgs)


     Protected Overridable Sub OnMyEventName(ByVal e as EventArgs)
         Raiseevent MyEventName(e)
     End Sub


    End Class


    2) In the derived class make a call to the overridable method: Me.OnMyEventName(New EventArgs). It's really just that easy. Do it all the time.


    Have Fun....

  3. 19 Mar 2004 at 16:06

    Error in the article "New Object-Oriented Capabilities in VB.NET - Events"


    Derived classes cannot raise base class events in VB.Net. Handle them sure, but not raise them - even if they are declared public. In order to achieve this handle the base class event and raise a derived class event instead.


    B.

  4. 02 Jul 2003 at 03:14

    How do we read the attributes in an XML file using a DataSet?

  5. 24 Feb 2003 at 08:50

    boig,


    I needed the same thing and found that I have it working using the Public Shared declaration on the class that contains my XMLDocument and the functions to access the document.  This makes the class available across the application.


    Public Shared  oTriggers As Triggers


    If you only need the XMLDocument I would give that a try.


    Hope this helps.

  6. 21 Nov 2002 at 04:46

    I need a global variable; but it is a "XmlDocument" object, does anybody know how do I have to create it, and how to initialitze it?

  7. 01 Nov 2002 at 06:35

    If you set a shared property of a user class in a ASP.NET application, how long wil the value last? Application level? Session level? Page level? Well i was actually looking for an answer to that when i got here...  useful article anyway even though it doesn't answer my question...

  8. 01 Jan 1999 at 00:00

    This thread is for discussions of New Object-Oriented Capabilities in VB.NET.

Leave a comment

Sign in or Join us (it's free).

AddThis

Related jobs

Events coming up

  • Dec 6

    Developing AJAX Web Applications with Castle Monorail

    London, United Kingdom

    Monorail is the model-view-controller engine of the Castle Project, bringing many of the best ideas of Ruby on Rails to the .NET world. In this talk, David De Florinier and Gojko Adzic show how Monorail makes it easy to develop .NET based AJAX applications, and how to use the Castle Project to build Web 2.0 applications effectively. Come to this session if you are a .NET web developer. Everyone is welcome!