Re :: Interface in VB 6.0
Saturday, November 22, 2008 12:04:22 AM
Inheritance for Visual Basic 6.0 Users
Inheritance allows you to create new classes from existing classes. Inheritance can simplify the design of the application by providing a relationship structure between the various classes. It also supports code reuse, because only the new or different class behavior must be coded.
 Interface Inheritance
Visual Basic 6.0
Visual Basic 2008
 Implementation Inheritance
When a new class is created through implementation inheritance, the new class automatically gains all the members and implementation of the base class. The existing class is called the "base class." The new class is the "derived class." Additional members can be added to the class. The behavior of the base class can be changed by writing code in the new class. This technique is called overriding.
You can create classes by inheriting from the classes you create, from classes in references you add to your project, or from objects in the .NET Framework. Many classes of the .NET Framework are related by inheritance. For example, the TextBox class inherits from the System.Windows.Forms..::.TextBoxBase class.
Visual Basic 6.0
Visual Basic 6.0 does not support implementation inheritance.
Visual Basic 2008
Inheritance is declared in Visual Basic 2008 by the Inherits statement. In this example, the derived class Oak inherits from a base class Tree.
Public Class Oak
Inherits Tree
' Add code here to extend or
' modify the behavior of the Tree class.
End Class
 MustInherit and NotInheritable
Visual Basic 6.0
In interface inheritance in Visual Basic 6.0, any class can act as an interface base class. There is no syntax for preventing any class to act as an interface base class. Likewise, there is no syntax to demand that a class act only as an interface base class.
Visual Basic 2008
Along with implementation inheritance, Visual Basic 2008 defines two class modifiers, MustInherit and NotInheritable. These modifiers let the programmer control the inheritance relationships in an application.
The MustInherit modifier on a class declaration indicates a class that cannot be instantiated:
Public MustInherit Class BaseClass
End Class
This means that BaseClass cannot appear after the New keyword. Only classes that inherit from BaseClass and that do not also have the MustInherit modifier can be instantiated. In object-oriented literature and in other object-oriented languages, a MustInherit class is called an abstract class. A class that is not a MustInherit class, one that can be instantiated, is called a concrete class.
A related concept is the sealed class, a class that cannot serve as a base class. The NotInheritable keyword on a class definition indicates this status:
Public NotInheritable Class DerivedClass
End Class
A NotInheritable class marks the edge of an inheritance hierarchy.
For more information, see Inheritance in Visual Basic.
 Upgrade Suggestions
Classes acting as interfaces in Visual Basic 6.0 are upgraded to interfaces in Visual Basic 2008. Consider this example of a base class and derived class from Visual Basic 6.0:
' Contents of class BaseClass
Public Sub BaseMethod()
End Sub
' Contents of class DerivedClass
Implements BaseClass
Private Sub BaseClass_BaseMethod()
End Sub
The Upgrade Wizard produces this upgraded code:
Option Strict Off
Option Explicit On
Interface _BaseClass
Sub BaseMethod()
End Interface
Friend Class BaseClass
Implements _BaseClass
Public Sub BaseMethod() Implements _BaseClass.BaseMethod
End Sub
End Class
Friend Class DerivedClass
Implements _BaseClass
Private Sub BaseClass_BaseMethod() Implements _BaseClass.BaseMethod
End Sub
End Class
Using inheritance instead of interfaces, the upgraded code can be modified to:
Friend Class BaseClass
Public Sub BaseMethod()
' Add code here to define BaseMethod.
End Sub
End Class
Friend Class DerivedClass
Inherits BaseClass
End Class
This eliminates one level of indirection, _BaseClass. Also, it eliminates one method definition, BaseClass_BaseMethod, because the method is inherited from the base class and does not need to be coded again. If the programmer wanted a different behavior for the derived class, the BaseMethod can be overridden as shown:
Friend Class BaseClass
Public Overridable Sub BaseMethod()
' Add code here to define BaseMethod.
End Sub
End Class
Friend Class DerivedClass
Inherits BaseClass
Public Overrides Sub BaseMethod()
' Add code here to define behavior for DerivedClass.
End Sub
End Class
Some techniques to consider in upgraded interfaces include:
-
Replace Interface statements with Inherits statements.
-
Implement the base class as an interface, rather than as a class that implements an interface. For more information see Interface Changes for Visual Basic 6.0 Users.
-
Implement base classes as MustInherit classes.
-
Implement derived classes as NotInheritable. Hope this helps. |
BiographyAsp.Net Developer Site Rank: Not applicable - Current Winnings: $0.00
Reply
Reply Using Power Editor
|
Interfaces in Visual Basic
Binny ch replied to RAJAN CRP
Saturday, November 22, 2008 12:57:25 AM
Visual Basic 6 does
not support inheritance or classes in the object-oriented sense of the
construct. VB6 does support COM interfaces. Defintion: http://msdn.microsoft.com/en-us/library/h9xt0sdd.aspx Example:
Option Strict Off Option Explicit On Interface _BaseClass Sub BaseMethod() End Interface
Friend Class BaseClass Implements _BaseClass Public Sub BaseMethod() Implements _BaseClass.BaseMethod End Sub End Class
Friend Class DerivedClass Implements _BaseClass Private Sub BaseClass_BaseMethod() Implements _BaseClass.BaseMethod
End Sub End Class
See this link: http://msdn.microsoft.com/en-us/library/yet634fk.aspx
|
BiographyBinny has not submitted biographical details. Site Rank: Not applicable - Current Winnings: $0.00
Reply
Reply Using Power Editor
|
read this link
C_A P replied to RAJAN CRP
Saturday, November 22, 2008 1:57:53 AM
http://msdn.microsoft.com/en-us/library/ms973861.aspx http://codebetter.com/blogs/eric.wise/archive/2005/06/02/63971.aspx
tutorial http://www.lubankit.org/InheritanceTutorial.htm http://java.sun.com/docs/books/tutorial/java/concepts/interface.html http://articles.techrepublic.com.com/5100-10878_11-5032721.html
|
BiographyC_A has not submitted biographical details. Site Rank: Not applicable - Current Winnings: $0.00
Reply
Reply Using Power Editor
|
About interface in vb 6.0
Saturday, August 29, 2009 1:59:20 AM
BiographySuraj has not submitted biographical details. Site Rank: Not applicable - Current Winnings: $0.00
Reply
Reply Using Power Editor
|
|
|