Page 190 - DCAP312_WEB_TECHNOLOGIES_II
P. 190
Web Technologies-II
Notes message i.e., self. Self (equivalent to this in Java) represents the receiver of the message. The
lookup of messages sent to self starts in the class of the receiver (as shown in the Figure 9.6 When
we define a method in a subclass it can hide method in superclasses. To access such hidden
methods of a superclass messages should be sent to super and not self. Super represents also
the receiver of the message but the lookup of messages start in the superclass of the class of the
method which issued the super invocation. In Figure 9.6, the method fullPrintOn: is looked up
in the class of the receiver EllipseMorph which does not define it, therefore the lookup continues
inBorderedMorph the superclass of EllipseMorph. This class defines the method which then gets
executed. The expression super fullPrintOn, aStream is then executed. The lookup then starts in
the superclass of BorderedMorph – note that the receiver class is not involved to determine where
to start the lookup. This method is defined in the superclass so it is executed.
Self is said to be dynamic in the sense that it always represents the receiver of the message. This
means that all the messages sent to self are looking up by starting in the receiver’s class. For
example in Figure 9.7 the message fullPrintOn, is sent to anEllipseMorph therefore the lookup
of the method colorString, invoked in the class Morph in the expression self colorString, aStream
(B) starts in the class of the receiver: EllipseMorph (C).
Note that the model we presented is conceptual in the sense that the virtual machine implementers
use all kind of tricks and optimizations to speed up the method lookup. The main point here is
to understand what the semantics of self and super.
Figure 9.7: Looking up by Starting in the Receiver’s Class
To access hidden methods of a superclass messages should be sent to super
and not self.
9.6.4 Abstractness
To finish with the precisions, a class can be abstract. However, there is no dedicated construct
for that. A class is considered abstract if one of its method contains the expression self
184 LOVELY PROFESSIONAL UNIVERSITY