| Home | Previous Lesson: Concrete Class Next Lesson: Methods |
Unlike passive data items in traditional systems, objects have the ability to act. An action occurs when an object receives a message, that is, a request asking the object to behave in a certain way.
When an object sends a message to another object, the sender is requesting the receiver to perform the named service and possibly return some information. When the receiver receives the message, it performs the requested service in any way that it knows. The request doesn't specify how a service has to be performed - such information is always hidden from the sender.
The set of messages to which an object can respond is known as the behavior of the object. However, not all messages that an object can respond to needs to be part of its publicly accessible interface. An object can send private messages to itself, to implement publicly accessible services.
For example, suppose a drawing object has received a message to draw a pie chart. The object may internally call a method to calculate the percentage of each member in the pie chart. However, if you send a message to the object to calculate the percentages for each member, it would result in an error saying that this service isn't available. Since it is private, it can be called only by another method of the same object.
| Home | Previous Lesson: Concrete Class Next Lesson: Methods |