Object's Data

Monday, January 14, 2008

Object's Data

Object's Data

Each object need to keep the information on how to perform its defined behavior. Some objects also contain variables that support their bahavior. These variables are called instance variables. Only the instance method for an object can refer to and change the values stored in the instance variables. The instance methods for other objects cannot refer to this object's data. An object may only access another object's data by sending it messages.This is called encapsulation and assures that there is a secure process for getting to an object's data.

Refer to the following diagram, the instance variables variableOne through variableX can only be accessed by the sender via instance methods methodOne through methodX. The sender can not refer to the variables directly by itslef.


Unlike procedural progamming where common data areas are often used for sharing information, object-oriented programming discourages direct access to common data (other than the use of global variables) by other programs. Only the object that "owns" the data can change its contant. Other objects can view or change this data by sending message to the "owner."

The instance variable names can be identical to the method names that associate with them. For example, the Student object has methods of name, address, and major as well as instance variables of name, address, and major. Smalltalk distinguishes variable identifier and a method identifier by the identifier's position in the expression.

0 comments:

 

Tamil Video Songs | Make Money Online