Characteristics of an Object—Its Properties

Look at your average candle. How would you describe it? You might say that it is three inches long, red in color, tapered, with a cotton wick at the top. Each of these descriptive characteristics is what is known in OOP terminology as a property (also known as an instance variable) of the object. Each object has properties that describe it.

To move back to programming concepts, for a minute, take a look at the old FoxPro 2.6 push button. What might the properties of that be? Well, for a few, the caption (e.g., OK, CANCEL), width and height of the button, location on the screen (a.k.a. form), etc., are all properties of the push button.

That's all there is to properties.

Going back to our customer example, where we define what the object is, we could have many properties for a customer. For example, the customer's name, address, telephone number, credit limit, etc., would all be properties of a customer.

The beauty of the OOP model is that properties become directly referenceable as part of the object. Let's take the example of changing the prompt (i.e., the Caption) of a push button. In FoxPro 2.6, we would modify the button attached to the variable, lhOk, with the following command:


SHOW GET m.lhOk,1 PROMPT "It's OK"

In an OOP programming environment, you access the property directly as part of the object. For example, here's a common syntax for this:


lhOk.Caption = "It's OK"

Notice the use of the dot operator. The idea behind this bit of code says that there is an object on the screen called lhOk that has a property called Caption (which controls what the user sees as the prompt for that object). This line of code sets the caption property to "It's OK," which will then automatically update the display of the object on the form.

Here's another one. Disabling an object is also likely done is a similar manner. In the old way, an object on a screen is disabled with:


SHOW GET lhOk DISABLE

as opposed to the OOP way that would be something like:


lhOk.ENABLED = .F.

which would automatically disable the object. You could also hide an object with:


lhOk.VISIBLE = .F.

Note the change in approach to modifying the characteristics of an object. In the old way, we did it indirectly using commands that work on the screen. Now, we are working directly on the object itself.

Changing the properties of a customer object work the same way. For example, to set the name of a customer, we could modify the customer's NAME property as follows:


Customer.Name = "Flash Creative Management, Inc."