Classes and Instances

In Rexx, objects are organized into classes. Classes are like templates; they define the methods and variables that a group of similar objects have in common and store them in one place.

If you write a program to manipulate some screen icons, for example, you might create an Icon class. All Icon objects will share the actions and characteristics defined by the class:

A Simple Class

All the icon objects will use common methods like DRAW or ERASE. They will have common variables like position, color, or size. What makes each icon object different from one another is the data assigned to its variables. For the Windows System icon, it might be position="20,20" while for the Shredder it is "20,30" and for Information it is "20,40"

Icon Class

Objects that belong to a class are called instances of that class. As instances of the Icon class, the Windows System icon, Shredder icon, and Information icon acquire the methods and variables of the class. Instances behave as if they each had their own methods and variables of the same name. All instances, however, have their own unique properties-the data associated with the variables. Everything else can be stored at the class level.

Instances of the Icon Class

If you must update or change a particular method, you only have to change it at one place, at the class level. This single update is then acquired by every new instance that uses the method.

A class that can create instances of an object is called an object class. The Icon class is an object class you can use to create other objects with similar properties, such as an application icon or a drives icon.

An object class is like a factory for producing instances of the objects.