(1) An object typically hides its data, but allows outside code to access its methods. As shown in the Figure (specified below), the object’s methods provide programming statements outside the object with indirect access to the object’s data attributes.
(Code outside the object interacts with the object’s methods.) When an object’s data attributes are hidden from outside code, and access to the data attributes is restricted to the object’s methods, the data attributes are protected from accidental corruption. In addition, the code outside the object does not need to know about the format or internal structure of the object’s data. The code only needs to interact with the object’s methods. When a programmer changes the structure of an object’s internal data attributes, he or she also modifies the object’s methods so that they may properly operate on the data. The way in which outsidecode interacts with the methods, however, does not change.