Visual Basic

  1. Home
  2. Computing & Technology
  3. Visual Basic
Objects! (and Methods and Properties)
5 - Objects in General
Lesson 2
Objects!

1 - The Word VBA Macro Reconsidered

2 - The Nature of OOP

3 - So What Are Methods and Properties?

4 - The Word Object Model

5 - Objects in General


If you read other books and technical articles about OOP, many of them will claim that Microsoft Visual Basic 6 (the VB version that is 'under the covers' in Word 2000 VBA) isn't even object oriented in the first place.

"Scoff, scoff, chortle, chortle!" They say, "VB 6 is just a toy language pretending to be object oriented! It doesn't even implement inheritance. Chortle, chortle, scoff, scoff!"

To this claim, I have several levels of response:

Sez you!! There is no international standard that defines what is, and what is not, 'object oriented'. Microsoft created Visual Basic to give programmers the greatest 'bang' for their programming buck. I say they did a pretty good job with OOP in VB 6 and the fact that it's the most widely used programming language says it all. The people who make this claim usually do it so they can hold up their favorite programming language as the ideal OOP language. Well ... VB is my favorite programming language and I say it hits that sweet spot of what is as OOP as possible without being so complex that you can't get anything done!

If you want a more complete and more complex type of OOP, try VB .NET! This version of VB implements OOP 'to the nines'! INCLUDING inheritance. We're doing VBA as implemented in Office because a lot of people have this software already and it's a lot easier to learn. It's a proven and effective technology that you can get a lot of productivity from. Besides, VB .NET isn't quite out for Office applications yet (September 2003 -- it's very close now).

With that said, let's look at what they're talking about.

(Note: You don't have to know any of this to write VBA programs. If you just want to skip the rest of this section and move ahead to the next lesson, go right ahead!)

Traditionally, an OOP programming technology incorporates three features:

  • polymorphism
  • encapsulation
  • inheritance

Polymorphism means that objects can do different things when they're used differently. "Poly" meaning "many" and "morph" meaning "form or shape". So, for example, if you have a Printer object, it will do something entirely different for a desktop ink jet printer versus a high-speed printing press. Visual Basic 6 implements Polymorphism quite well.

Encapsulation means that an object can be treated as a "black-box". We can use it without understanding the details of how it works. This is also sometimes called "data-hiding". The details that make an object work are "hidden". If you have a Printer object, you don't know how it sends stuff to be printed. You only know how to send stuff to be printed to it. Visual Basic 6 also implements encapsulation.

Inheritance lets you write a program that creates a new object by basing it on an existing one. If you have a BasicPrinter object, you can create an ink jet printer object by inheriting all the methods and properties of BasicPrinter and then just building on them. Visual Basic 6 doesn't allow you to do this, but VB .NET does! One example of the complexities of inheritance is that different "fully OOP" languages have some very significant differences in the way they implement it. C++, for example, implements what is called "multiple inheritance" and Java does not.

Enough Theory! It's about time to get back to what we're really here for: writing programs! In the next lesson, we write a program that could actually be quite useful to you! Look for it!

Explore Visual Basic

By Category

About.com Special Features

Visual Basic

  1. Home
  2. Computing & Technology
  3. Visual Basic

©2009 About.com, a part of The New York Times Company.

All rights reserved.