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

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

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 "State" by one may look like the following}


{Then to decrease the Vector's Count "State" by one may look like the following.
Note that the variable "ElementX" represents a number to the element you wish to erase. In this case the element is the closing price of a stock.}


From that, I hope my readers now understand, in most OO languages, including Easy Language OOEL, we manipulate the State of an Object via its methods. And the methods define an object's "Behavior", and its "States" are kept in Class variables, such as the Vector's Count variable in the example above.

See some powerful OOEL Indicators and Strategies "OOEL Indicators and Strategies".