In object-oriented programming, objects are modeled to real-world objects. A real-world object has:
Take a ball, for instance. A ball can be acted on--rolled, tossed, thrown,
bounced, caught. But it also has its own physical characteristics--size,
shape, composition, weight, color, speed, position. An accurate data model
of a real ball would define not just the physical characteristics of size,
shape, and the rest. Rather, this is what conventional programming would
do. Instead it would define all related actions and characteristics
in one complete "package." Aballobject
┌─────────BOUNCE──────────┐
│ │
│ │
│ Size |
T Shape C
H Comp A
R Weight T
O Color C
W Speed H
│ Pos |
│ │
│ │
└─────ROLL───────TOSS─────┘
In object-oriented programming, objects are the basic building blocks--the fundamental units of data.
There are many kinds of objects; for example, character strings, collections,
and input and output streams. An object--such as a character string--always
consists of two parts: the possible actions or operations related to it,
and its characteristics, or variables (a variable has a variable name,
and an associated data value that can change over time). These actions
and characteristics are so closely associated that they cannot be separated.
Ball object with variable names and values
┌─────────BOUNCE──────────┐
│ │
│ │
│ Size=3 |
T Shape=round C
H Comp=rubber A
R Weight=2 T
O Color=yellow C
W Speed=32 H
│ Pos=4 |
│ │
│ │
└─────ROLL───────TOSS─────┘
To access an object's data, you always need to specify an action. For example,
suppose the object is the number 5. Its actions might include addition,
subtraction, multiplication, and division. Each of these actions is an interface
to the object's data. The data is said to be encapsulated because
the only way to access it is through one of these surrounding actions. The
encapsulated internal characteristics of an object are its variables.
Variables are associated with an object and exist for the lifetime of that
object.
Encapsulated 5 object
┌───────SUBTRACTION───────┐
│ │
A D
D I
D V
I I
T 5 S
I I
O O
N N
│ │
│ │
└──────MULTIPLICATION─────┘
REXX comes with a basic set of classes for creating objects (see The Basics of Classes). Therefore, you can devise objects that exactly match the needs of a particular application.