Object Oriented Concepts: Part 2

General Development Concepts

Part 2 in the OO series. Messages.

Date : 2006-04-19
Object Oriented Concepts

Lesson 2: Messages

By itself, a single object isn't of much use. That's why objects are generally implemented as smaller pieces of a larger program along with lots of other objects that meld to achieve a given task. The combination of these objects is more than the sum of their parts: more functionality and more complex behaviors. To use the example from our previous article, a lamps pieces - the bulb, the base, the cord, are all pretty useless by themselves, but once you put them all together they give you light.

But from the standpoint of a real programmer, how do you use these different objects together? This is where messaging comes in. Software objects interact with each other by sending messages to one another. When one objects wants another object to do something it lets it know by sending it a message.

To let the receiving object know what we want from it the sending object has to provide a message that contains all the paramaters that indicate how it should behave. These paramaters could be anything from a string to an integer or a whole cart full of other information but when it comes right down to it there are only three parts to a message, these are:

1. The object which is to be addressed
2. The name of the method to be performed
3. And any parameters needed by the method

These three parts are all that the receiving object needs to translate the message into an action. Sometimes it isnt even necessary to pass a paramater and the message can be sent with just an object name and the name of the method to execute. This is often the case if you are just kicking off procedures in the target object.

So messages are really pretty basic in and of themselves. They are simply delivery mechanisms used to tell the object what you want it to do.

To break it down, there are two primary benefits of messages:

1. An object accomplishes what it does by means of its methods so a message passed to or from an object supports any activity that is needed.
2. Messages can be sent back and forth between objects regardless of whether they are in the same process or even the same machine.

Next up, Classes!

Comments :

No comments yet
  • Search For Articles