Thursday, March 11, 2010

Messages and Responsibilities

Members of an object-oriented community make requests of each other. The next
important principle explains the use of messages to initiate action:
Action is initiated in object-oriented programming by the transmission of a
message to an agent (an object) responsible for the actions. The message
encodes the request for an action and is accompanied by any additional
information (arguments/parameters) needed to carry out the request. The
receiver is the object to whom the message is sent. If the receiver accepts the message, it accepts responsibility to carry out the indicated action. In
response to a message, the receiver will perform some method to satisfy the
request.

There are some important issues to point out here:
• The client sending the request need not know the means by which the request
is carried out. In this we see the principle of information hiding.
• Another principle implicit in message passing is the idea of finding someone else
to do the work i.e. reusing components that may have been written by someone
else.
• The interpretation of the message is determined by the receiver and can vary
with different receivers. For example, if you sent the message “deliver flowers”
to a friend, she will probably have understood what was required and flowers
would still have been delivered but the method she used would have been very
different from that used by the florist.
• In object-oriented programming, behaviour is described in terms of responsibilities.
• Client’s requests for actions only indicates the desired outcome. The receivers
are free to pursue any technique that achieves the desired outcomes.
• Thinking in this way allows greater independence between objects.
• Thus, objects have responsibilities that they are willing to fulfill on request. The
collection of reponsibilities associated with an object is often called a protocol.

No comments:

Post a Comment