Modules and Classes

I seem to remember reading somewhere that a Module and a Class are sort of similar in the way they are constructed (not the way they work). So if I have a Module with a whole lot of Methods and Properties, would that be fairly easily turned into a Class.

Despite Paul’s best endeavours with his OOP101 and OOP201, I am still a little “wary” (I think that’s the word I want) of Classes. So if my question above can be answered positively, then I am sure I can work something out.

both Modules and Classes can contain Methods and Properties… but that is kind of where the similarity ends.

A Module exists once, and its methods can be called from any where in the application if they are PUBLIC, and only within the Module if they are Private.

A Class can be instantiated as many times a desired. And the properties of each instance can have values unique to that instance

The classic example is a class called CAR… all instances of cars have WHEELS (usually 4), and ENGINE, and a COLOR

The engine in each instance can be different. One can have a Boss302, the only and 289 … One might be Blue the other Red

Or a class might be PLAYING CARD, each instance has its own value for the properites RANK and SUIT

You can create an array (or dictionary) of classes…

dim myCars() as classCAR
myCars.append new classCar("Boss302","Red")
myCars.append new classCar("289","Blue")

This of course does not begin to touch on all the nuances of a CLASS object, but suffice it to say, once you get you head wrapped around them, you will wonder why it took you so long. :slight_smile:

Modules help you to organize your code, especially code that is not specific to a window or control. You could for example have a module MathsModule which contains all the maths functions you implement. After all these functions should be available everywhere, so putting them in a Window only is not good OOP. In turn these functions in the module might require local storage or items which should NOT be available everywhere.

Classes are the real building blocks of object oriented programming. They tell the computer what properties an object has and what it can do (methods). As such they are blueprints that the computer uses to build objects. For a computer EVERYTHING is an object, it is not sophisticated enough to distinguish between subject (a person) and object (a car) or between real (an apple) and virtual (a report).

A module behaves essentially like a static class would in C# then?