Building classes and using them in your code is fairly simple, but there are a few points about Object-Oriented Programming (OOP) that can cause confusion. To help you make the most of Object-Oriented Programming and get up to speed, I’m including a … [Read more...] about Classes versus Objects
Working with Objects
Objects versus Object Variables
All variables that refer to objects are called object variables. (The other type of variables are value variables, which store base data types, such as characters, integers, strings, and dates.) In declaring object variables, we usually use the New … [Read more...] about Objects versus Object Variables
Properties vs Fields / Shared vs Instance Members
Properties versus Fields When you set or read a property’s value, the corresponding Get or Set segment of the Property procedure is executed. The following statement invokes the Property Set segment of the EMail public property of the … [Read more...] about Properties vs Fields / Shared vs Instance Members
Type Casting – CType(), DirectCast()
The data type used most in earlier versions of the language up to VB 6 was the Variant (which was replaced in subsequent versions by the Object type). A variable declared as Object can store anything, and any variable that hasn't been declared … [Read more...] about Type Casting – CType(), DirectCast()
Early versus Late Binding
Untyped variables can't be resolved at compile time; these variables are said to be late-bound. An expression such as the following can't be resolved at compile time because the compiler has no way of knowing whether the object retrieved from the … [Read more...] about Early versus Late Binding
Inheritance – How to Apply Inheritance
Here's a scenario we're all too familiar with: You've written some code, perhaps a collection of functions, which you want to reuse in another project. The key word here is reuse: write once, use many times. For years, VB developers were reusing … [Read more...] about Inheritance – How to Apply Inheritance
Inheriting Existing Classes – Inheritance
To demonstrate the power of inheritance, we’ll extend an existing class: the ArrayList class. This class comes with the Framework and is a dynamic array. (See Chapter, "Storing Data in Collections," for a detailed description of the ArrayList class.) … [Read more...] about Inheriting Existing Classes – Inheritance
Inheriting Custom Classes – Inheritance
In this example, we'll tackle a very real problem by using inheritance. Consider a structure for storing product information; in most applications, this structure is optimized for a specific product type. In my experience, I've seen designs that try … [Read more...] about Inheriting Custom Classes – Inheritance
Polymorphism
A consequence of inheritance is another powerful OOP technique: polymorphism, which is the capability of a base type to adjust itself to accommodate many different derived types. Let's make it simpler by using some analogies in the English language. … [Read more...] about Polymorphism
Advantages of Implementing Polymorphism
In this section, you'll build a few classes to represent shapes to demonstrate the advantages of implementing polymorphism. Let's start with the example Shape class which we are going to discuss here, which will be the base class for all other … [Read more...] about Advantages of Implementing Polymorphism
Who Can Inherit What? – Inheritance
The Shape base class and the Shapes derived class work fine, but there's a potential problem. A new derived class that implements a new shape may not override the Area or the Perimeter method. If you want to force all derived classes to implement a … [Read more...] about Who Can Inherit What? – Inheritance
The MyBase and MyClass keywords
The MyBase and MyClass keywords let you access the members of the base class and the derived class explicitly. To see why they're useful, edit the ParentClass, as shown here: Override Method4 in the derived class, as shown here: Switch to … [Read more...] about The MyBase and MyClass keywords
The Class Diagram Designer
Classes are quite simple to build and use, and so is OOP. There are even tools to help you design and build your classes, which I’ll describe briefly here. You can use the Class Diagram Designer to build your classes with point-and-click operations, … [Read more...] about The Class Diagram Designer