Skip to main content

B. What is an Object's State and Behavior?

Posted in

What is an Object's State and Behavior in Object Oriented Programming?

For the most part, you can count on Objects having 2 very important characteristics:

1. a STATE and
2. a BEHAVIOR

For example, using our Vector class, first mentioned in the blog A. What is an Object, we defined a class like the following:

Vars:
Vector closingStockPrices(null);

closingStockPrices = new Vector; // This creates an instance of the class Vector

We created an instance of the Vector class, closingStockPrices, to hold the closing prices
of "X" number of stocks.

An example of changing an Object's "State" would be manipulating its Easy Language OOEL Count variable, which is the number of elements (closing stock prices) in the Vector. If our "closingStockPrices" Vector holds 10 stock prices, its Count "State" would equal 10.

A Behavior of a class are defined by their methods. Their methods of course manipulate an Object's State (It's important to know there are other usages of an Object's methods that will be discussed later).

As an example of manipulating a classes' State, would be adding elements using the Vector's "Insert" method, and removing elements using its "Erase" method, both manipulate the State "Count." Further, the methods Insert and Erase are part of a Vector's behavior ( The full definition of a Vector's behavior is defined by the rest of the Vector's methods).

The Following is a TradeStation OOEL Code Example:

{The code to increase the Vector's Count "S