Export (0) Print
Expand All

Class and Interface Changes in Visual Basic

Visual Studio .NET 2003

Visual Basic .NET introduces a number of changes that affect the declaration and usage of classes and interfaces.

Implements Statement

Visual Basic 6.0

In Visual Basic 6.0, a class definition implicitly includes a default interface, which defines the public members of the class. This interface can be referenced by another class. In particular, a class can specify another class name in an Implements statement.

Visual Basic .NET

In Visual Basic .NET, classes can have methods, and you can define interfaces explicitly. The properties and methods of a class belong exclusively to the class itself. The Implements statement can specify only an interface, not another class.

Global Classes

Visual Basic 6.0

When you create a new class in Visual Basic 6.0, the allowable values of the Instancing property include GlobalSingleUse and GlobalMultiUse. These indicate that other components can invoke the properties and methods of the new class as if they were global functions. An instance of the class is implicitly created the first time one of its members is called. This functionality enables a server to expose properties and methods that can be accessed without qualification.

Visual Basic .NET

Visual Basic .NET provides the same functionality by allowing you to expose standard module members from a server. You can add properties and methods of a shared class to the System namespace using the Imports statement. Visual Basic .NET does not support the Instancing property. You can achieve the effect of GlobalMultiUse with Public class access and the appropriate constructor access.

Option Private Module Statement

Visual Basic 6.0

In Visual Basic 6.0, the Option Private Module statement indicates that the entire module is private, and its components are not accessible outside its project.

Visual Basic .NET

Visual Basic .NET does not support the Option Private Module statement. This specification is handled by access modifiers in the Module statement.

Default Members

Visual Basic 6.0

In Visual Basic 6.0, you can specify that any particular method or data member is the default member of a class.

Visual Basic .NET

In Visual Basic .NET, a default member of a class or structure can only be a property that takes one or more arguments. This enables interoperability with other programming languages.

Initialization and Termination

Visual Basic 6.0

In Visual Basic 6.0, class modules use the Initialize and Terminate events to perform any necessary actions at the time of creation and destruction. The Initialize event is raised when the object is first encountered following a New statement, and Terminate is raised as soon as the last reference to the object is released. However, you can also call these event methods directly at any time during execution.

Visual Basic .NET

Visual Basic .NET uses the constructor/destructor model, and does not support Class_Initialize and Class_Terminate. A class uses the Sub statement to declare its constructor. This enables support of inheritance, which requires parameterized constructors. It also protects the constructor and destructor from being called except at creation and termination.

Indeterminate Lifetime

Object lifetime is determined by the creation and termination of the object instance. The program determines the creation time of the objects it declares, but termination involves a more complex mechanism.

Visual Basic 6.0

In Visual Basic 6.0, every object instance maintains a reference count. When the last reference to an instance is released and the count goes to zero, the object is terminated immediately.

Visual Basic .NET

In Visual Basic .NET, a destructor is not necessarily called as soon as the last reference is released. This is because the common language runtime maintains a reference tree instead of individual reference counts. The garbage collector traces the reference tree in the background. If it finds an object or group of objects that have no reference from any currently executing code, it calls the destructors of all such objects. It is impossible to predict either the order of this destruction or the time it takes the garbage collector to trace the reference tree. Therefore, the lifetime of an object is indeterminate.

See Also

Implements Statement | Imports Statement | Object Data Type | Class Statement | Structure Statement | Module Statement | Sub Statement | New | System Namespace | Object Lifetime: How Objects are Created and Destroyed | Automatic Memory Management | Programming Element Support Changes Summary

Show:
© 2014 Microsoft