Types of messages
There are 3 types of messages that an object may receive: informative messages, interrogative messages, and imperative messages.
Important
- informative message
An informative message is a message to an object that provides the object with information to update itself. (It is also known as an update, forward, or push message.) It is a "past-oriented" message in that it usually informs the object of what has already taken place elsewhere.
Example: emplyee.gotMarried(marriageDate:Date, toWhom:Person).
Most "setter" methods fall in this category.
An informative message tells an object something that's happend in the part of the real world represented by that object.
Important
- interrogative message
An interrogative mesaage is a message to an object requesting it to reveal some information about itself. (It is also known as a read, backward, or pull message). It is a "present-oriented" message, in that it asks the object for some current information.
Example: hom1.location message asks hom1 to tell us the location
most getter messages fall in this category.
Important
- imperative message
An imperative message is a message to an object that requests the object to take some action on itself, another object, or even the environment around the system. (It is also known as a force or action message.) It is a "future-oriented" message, in that it asks the object to carry out some action in the immediate future.
Example from the hominoid: hom1.advance().
This kind of action usually has some (more or less) complicated algorithm behind it.
Example: hom1.goToLocation(square:Square, out feasable: Boolean) would have to find a way to that location first...
Real-World example: robotLeftHand.goToLocation(x,y,z:Length, theta1, theta2, theta3:Angle) would ask a robot arm to actually move.
Example from the bomb:
timer.tick() may tell the timer that another second has passed. This is an informative message.
timer.setTime(time:int) sets the timer to a certain value. This is an informative message. may also be imperative (if something else happens, like the timer starts)
bomb.detonate() is called when the timer is expired. This is an imperative message.
Practice: Classify each one of the 4 messages from the earlier TV example (in this case the return doesn't count)
channelUp() (user -> Remote) imperative (demand action) / informative (real-world -> computer)
channelUp() (Remote -> TV) imperative (demand action)
getChannel() (TV -> Tuner) interrogative (need to know information)
setChannel() (TV -> Tuner) imperative (demand action)
A procedural progam consits of a set of instructions
An object oriented program consists of a set of messages between objects
Book: Chapter 1.5