OOP in VB6?

When you think of OOP (Object-Oriented Programming), VB6 is probably not what you have in mind.

But out of either 3 or 4 pillars of OOP (depending on when you read OOP), VB6 actually has 2 of 3 (or 3/4).

What are the pillars of OOP?

There were 3 generally known pillars of OOP back in the old days:

  • Encapsulation
  • Polymorphism
  • Inheritance

Out of these 3, VB6 supports the first two: Encapsulation and Polymorphism.

Inheritance (in the sense that data and implementation are inherited) is not supported, but VB6 does have the “Implements” keyword which is normally used to create polymorphism, allows a class to inherit the public methods but not the data and implementations.

Encapsulation is the easiest to understand since it’s just a way to hide certain class data from consumers of the class.
But hiding “per se” can be done by declaring data as “private” — so a better way to describe encapsulation, is a way of providing mechanisms to access protected data.

Polymorphism essentially means “many forms”. In VB6 this is achieved by creating a base (abstract) class and then making different (concrete) implementations of it (via the “Implements” keyword). This allows you to write programs that can have very dynamic behaviors at runtime and makes it easy to extend after release (similar to Open-Closed Principle [OCP]).

On the next articles, I’ll demonstrate how to do these things in VB6.

Leave a Comment