vb logo

 

Visual Basic Books
Home
Visual Basic Beginner Books
Visual Basic Database Books
Visual Basic ActiveX Books
Visual Basic Advanced Books
VB Internet Programming Books

Resources
Visual Basic Links
Add a Link
Subscribe to Mailing List

Visual Basic Books

Programming Microsoft Visual Basic 6

Chapter 6

Classes
and Objects

Your users will never see a class; rather, they’ll probably see and interact with objects created from your classes, such as invoices, customer data, or circles on the screen. As a programmer, your point of view is reversed because the most concrete thing you’ll have in front of you while you’re writing the application is the class, in the form of a class module in the Visual Basic environment. Until you run the application, an object isn’t more real than a variable declared with a Dim statement in a code listing. In my opinion, this dichotomy has prevented many Visual Basic programmers from embracing the OOP paradigm. We have been spoiled by the RAD (Rapid Application Development) orientation of our favorite tool and often think of objects as visible objects, such as forms, controls, and so on. While Visual Basic can also create such visible objects—including Microsoft ActiveX controls—you won’t grasp the real power of object orientation until you realize that almost everything in your program can be an object, from concrete and visible entities such as invoices, products, customers, employees, and so on to more abstract ones such as the validation process or the relationship between two tables.

The Main Benefits of OOP

Before getting practical, I’d like to hint at what object-oriented programming has to offer you. I’ll do that by listing the key features of OOPLs (object-oriented programming languages) and explaining some concepts. An understanding of these ideas will turn out to be very useful later in the chapter.

Encapsulation

Encapsulation is probably the feature that programmers appreciate most in object-oriented programming. In a nutshell, an object is the sole owner of its own data. All data is stored inside a memory area that can’t be directly accessed by another portion of the application, and all assignment and retrieval operations are performed through methods and properties provided by the object itself. This simple concept has at least two far-reaching consequences:

  • You can check all the values assigned to object properties before they’re actually stored in memory and immediately reject all invalid ones.
  • You’re free to change the internal implementation of the data stored in an object without changing the way the rest of the program interacts with the object. This means that you can later modify and improve the internal workings of a class without changing a single line of code elsewhere in the application.

next page....

Email us your comments:mail
Fax: 1(916)404-7719
©1999 Valassis Enterprises. All rights reserved.