The structures of all classes are pretty well the same regardless of the programming language being used. And really that's the whole point of them. A programmer needs know nothing about the internal workings of a class. Often they don't even need to know what programming language it was written in. All they need to know is:
- the properties of the class
- the methods of of class
The programmer can then go on and use this class in their own applications. And, for the new programmer, VBScript (or Visual Basic Script) is a particularly good place to start. That's because:
- it is very easy to create and use a class with VBScript
- VBScript is built into every Windows computer
And all that's required is a text editor. Notepad will suffice, but there are editors designed for the job (and free) such as the Programmer's Notepad.
Creating Classes and adding Properties
The first step is to create a class. The class will then need properties (the information about a class, such whether it has a color or legs). Both the creation of the class and addition of properties are covered in Starting Object Oriented Programming in VBScript: How to Create, Use and Reuse OOP Classes in a VBScript Application.
Special Methods of a Class
As well as properties a class will have special methods. These run automatically, for instance:
- when the object is instantiated
- when the object is terminated
And they're discussed in How to Initialise and Terminate a VBScript Class: Creating VBScript Subroutines That Run When a Class is Instantiated.
There are other special methods that are run when properties are updated or read which are discussed in Using a Property Let and Get in a VBScript Class: How to Work with an Object's Properties and VBScript Programming.
Public and Private Methods of a Class
The programmer can add their own customized methods to a VBScript Class. These methods can be one of two types:
- private – these can only be used within the class
- public – these are visible to the users of the class
These can be seen in operation in a simple class:
It is now possible to instantiate objects from this class and those objects can start to communicate with each other:
The end result can be seen in figure 1 at the bottom of this article. They show just how easy it is to add private and public methods to class, and that not only can a programmer communicate with objects, but the objects can actually communicate with each other.