Classes: Where Objects Come From

Where do objects come from? This is a little like asking: where do houses come from? or for that matter, where do cars come from?

The answer is: from blueprints. Houses are built according to architectural blueprints, and cars are built according to engineering blueprints. The blueprints from which objects are made are called classes.

What classes look like

You can think of a class as a pattern for creating objects. A class just lists the data members of the objects that will be created from it, and also the methods (lists of instructions) that each object of the class will have. The language we will be using is Visual Basic, or VB. In VB, a class looks like this:

class MyClassName
 
 data members
 
 methods
 
 data members
 
 methods

end class

Visual Basic Programs

It is time to look at some programs. A VB program will typically have many objects created from different classes. If the program has a graphical user interface (called a GUI) one of those objects will be a window, created from the Window class. The importance of the Window object is that it represents the program's user interface on the screen.

Let us create a simple GUI program, and use it to illustrate the various concepts that are involved in Windows programming.

Visual Studio

We use a tool called Visual Studio to create VB programs. Open Visual Studio using instructions provided by the instructor, making sure to select Visual Basic for the programming language, and Windows Forms for the type of project. A VB program is a collection of files, and such a file is called a project. When Visual Studio asks for the name of the project, type in GameCamp1 (You can actually use any name that you like.)



Previous Next