Windows Phone Developers

Showing posts with label VB.NET Abstract classes. Show all posts
Showing posts with label VB.NET Abstract classes. Show all posts

Saturday, September 18, 2010

Abstract Classes in VB.NET

Abstract classes are base classes that has to be inherited.  A class can be made as an abstract with MustInherit modifier

Abstract classes can contain abstract methods also. Abstract methods are the ones where only signature is available in the base class and their implementation is taken care in derived classes.

Following is an example of abstract class:

Public MustInherit Class ClassAbs



    Public Sub ExampleMethod()

        MessageBox.Show("This is sample")

    End Sub

    Public MustOverride Sub ExampleMethod_ShouldBeInherited()



    Public Overridable Sub ExampleMethod_CanBeCalledFromBase()

        MessageBox.Show("This is sample")

    End Sub

End Class


the class contains one Abstract method

The class can be inherited as shown below:

Public Class ClassDerivedFromAbstract
    Inherits ClassAbs

    Public Sub ExampleAbstract()

        MyBase.ExampleMethod_CanBeCalledFromBase()


    End Sub

    Public Overrides Sub ExampleMethod_ShouldBeInherited()


    End Sub

    Public Overrides Sub ExampleMethod_CanBeCalledFromBase()

        MessageBox.Show("This is sample from Derived")

    End Sub

End Class


The class can be used as shown below:

Dim CAb As New ClassDerivedFromAbstract

        CAb.ExampleMethod_CanBeCalledFromBase()
        CAb.ExampleMethod_ShouldBeInherited()


the first call uses the method from the base class and the second one uses the Method we had overriden in the derived class Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

Saturday, October 11, 2008

What is an Abstract Class / Abstract Classes in C#

Abstract classes are the ones that do not require instantiation. Abstract classes should never be instantiated, it is important to correctly define their constructors. It is also important to ensure that the functionality of your abstract class is correct and easily extended

Abstract (MustInherit in Visual Basic) classes can behave like interfaces or regular classes in that they can define members, and they can provide implementation details but are not required to do so. If an abstract class does not provide implementation details, concrete classes that inherit from the abstract class are required to provide the implementation.

For more info please visit msdn.microsoft.com

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon