Message Passing


Objects communicate with one another by sending or receiving information to or from each other. A message for an object is a request for execution of a procedure and therefore will invoke a function in the receiving object that generates the desired results. Message passing involves specifying the name of the object, the name of the function and the information to be sent.

For example, in the car-dealer case study, the main method has the following message passing:

public class TestVehicle {
  public static void main( String[ ] args ) {
    ...
    Sale veh1 = new Sale( "FG1000", args[0], "B-Class",  100000.00, 25000 );
    ((Sale) veh1).setDepreciation( 20.0 );
    ...
  }
}

Cohesion
Cohesion refers to the level of a component which performs a single well-defined task. A single well-defined task is done by a highly cohesive method. The weakly cohesive method will split the task into separate parts. The java.io package is a highly cohesive package because it has I/O related classes and interfaces. However, the java.util package is a weakly cohesive package because it has unrelated classes and interfaces.

Review: Object-Oriented Programming Concepts
    Which term is used to describe the method of hiding internal details and showing only functionality?

      Abstraction
      Cohesion
      Composition
      Coupling
        Result:




      “The only way to get through life is to laugh your way through it.    
      You either have to laugh or cry.    
      I prefer to laugh.    
      Crying gives me a headache.”    
      ― Marjorie Pay Hinckley