Re: Does one "call a method" when polymorphism is used?
- From: andrewmcdonagh <andrewmcdonagh@xxxxxxxxx>
- Date: Fri, 4 Jan 2008 12:19:03 -0800 (PST)
On Jan 4, 3:39 pm, r...@xxxxxxxxxxxxxxxxxx (Stefan Ram) wrote:
I wonder what the correct wording for the following situation is:
void print( final java.lang.Object object )
{ java.lang.System.out.println( object.toString() ); }
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Without further thinking, one might say »The method
"toString()" is being called here.«.
However, according to the JLS, a methode is a specific member
of a specifc class. »toString« above does not denotate such an
entity, because for each invocation the method activated will
be determined only at run-time.
»toString()« yields a signature which is used at run-time to
choose a method. Sometimes (in the case of other identifiers
than »toString«) a method might not even be found in the
target object's class, so actually this is at most a »call
attempt«.
To call this »to call a method« might be misleading, because
it hides the indirection via late-binding and gives the wrong
impression that »toString()« indicates a specific method of a
specific class, while it really is only used to choose a
method at run time.
So, is there a more appropriate and precise wording?
The first two ideas that come to my mind would be to say »to
call a signature« or »to call an identifier«.
I believe that the last idea is better, because »identifier«
is used in the JLS3's description of the syntax of this
invocation pattern and it also takes into consideration that
the identifier expresses the intention of the author, while
there might be multiple possible signatures depending on minor
details for an identifier (like in »print("a")« and »print(2)«).
But »to call an identifier« is unusual and also not contained
in the usual sense of the verb to »call«. The second problem
might be addressed by using »to call /via/ an identifier«,
which also hints at the indirection.
From a OO PoV, the toString() is a 'Message' that is being sent to the
object. The object decides at runtime how to handle that Message,
depending upon the virtual nature of the method - i.e. has the method
toString() been over ridden?
An easy way of understanding this, is if you used Java's reflection
API to obtain a reference to the method from the obj's class.
Alternativitly, if you understand dynamically typed languages like
Python, Ruby, Smalltalk, etc., then these behave exactly like the
description above. With the code like "obj.2String()" compiling, but
failing at runtime as the is no method defined that can handle the
Message.
Andrew
Andrew
.
- Prev by Date: Re: What Size Screen Do You Design For?
- Next by Date: Re: What Size Screen Do You Design For?
- Previous by thread: Re: Does one "call a method" when polymorphism is used?
- Next by thread: Re: Does one "call a method" when polymorphism is used?
- Index(es):