Contents    Page-10    Prev    Next    Page+10    Index   

Message Sending

Sending a message is just a function call. However, the specific function ( method) that is actually called is determined dynamically by the runtime type of the object to which the message is sent ( dynamic dispatch).


            Drawable
           /        \ 
          /          \ 
     Circle           Square
 draw: circle_draw()    draw: square_draw()
     /
    /
  obj

Suppose we execute: obj.draw(x,y)

  1. Find the method corresponding to the message selector. Since obj is a circle, draw is looked up as circle_draw().

  2. Assemble the arguments:
    obj.draw(x,y) becomes circle_draw(obj,x,y). obj is the (hidden) this argument of the function.

  3. Call the method function with the arguments as usual.