Let's suppose you've got a class defined (in pseudocode):
class Puppy {
// ...
string sound = "Rawr!";
void bark() {
print(sound);
}
}
And say, given a Puppy
instance, you call it's bark()
method:
int main() {
Puppy p;
p.bark();
}
Notice how bark()
uses the member variable sound
. In many contexts, I've seen folks describe sound
as the member variable of the "calling object."
My question is, what's a better term to use than "calling object"?
To me, the object is not doing any calling. We know that member functions are in a way just functions with an implicit this
or self
parameter.
I've come up with "receiving object" or "message recipient" which makes sense if you're down with the "messaging" paradigm.
Do any of you happy hackers have a term that you like to use?
I feel it should mean "the object upon which a method is called" and TOUWAMIC just doesn't cut it.
As for who the "caller" is, I would say that main
instantiates a Puppy
object and calls its bark()
method.
6 Answers 6
Using the word object in the reference is redundant.
Perhaps caller and callee is simplistic enough. Referring to the actual object as an instance of type is also another approach as noted by Wyatt; instance of Puppy or if being succinct is the goal...instance.
-
+1, for the clarified version I'd use 'caller' in most contexts.Wyatt Barnett– Wyatt Barnett11/15/2011 19:22:03Commented Nov 15, 2011 at 19:22
-
5I may be wrong, but I think "caller" is the object that invokes some method on
p
yati sagade– yati sagade11/15/2011 19:22:37Commented Nov 15, 2011 at 19:22 -
Well, not the object that invokes the method, but the scope within which the function in which the object's method is invoked, no? (eg,
main
above invokesp
'sbark()
method.)ybakos– ybakos11/17/2011 12:59:37Commented Nov 17, 2011 at 12:59 -
"Caller" and "callee" conventionally refer to (member) functions, not objects.
Puppy::bark()
is the caller; the calleeprint()
apparently is a non-member function.MSalters– MSalters11/17/2011 15:49:30Commented Nov 17, 2011 at 15:49
p
is the receiver, recipient, target, callee, "the puppy," or just "p".
The object sending the message/calling the method is the sender or caller. Caller can also mean the function or method calling p.bark().
Sometimes the relationship between the objects is used instead because that's an easier way to identify the two, so one might be the parent and the other the child, or one might be the delegate and the other the delegator.
-
-
"The object sending the message/calling the method is the sender or caller. Caller can also mean the function or method calling p.bark()." -- I agree with the second sentence, but not the first, if by 'object sending the message' you mean
p
above.p
isn't doing the calling.ybakos– ybakos11/17/2011 02:04:30Commented Nov 17, 2011 at 2:04 -
@ybakos No,
p
is the recipient/callee in the example. It might be the case thatp
is also the caller, but I wasn't assuming that and your example doesn't tell us anything about where the code that callsp.bark()
lives.Caleb– Caleb11/17/2011 03:13:46Commented Nov 17, 2011 at 3:13
Based on your comment in Wyatt's post:
Rather, how to describe p in the context of method calls.
I'd have to go with describing p
in the context of method calls as being the "method's instance".
In object-oriented programming, a method is a subroutine (or procedure or function) associated with a class. [Wikipedia]
As such, when describing the inverse relationship, I would believe that "method's instance" would be correct your described context (but exchanging class for instance as we're describing the relationship to the instance, not the class definition itself).
I'd go with any of:
- call target
- method owner (although this doesn't really make sense if
p
isnull
, because then it hardly owns anything) - callee
Although in that very context, I'd go with p
;)
I'd generally call p
an instance of Puppy, not the calling object
-
Thanks for the response, but I've edited the question a bit to provide more context. I'm not so concerned about how to describe what
p
is itself (I agree, it's an instance of the class). Rather, how to describep
in the context of method calls.ybakos– ybakos11/15/2011 19:19:25Commented Nov 15, 2011 at 19:19
The "Calling Object" is roughly equivalent to a dispatcher, so I guess you could use that term to describe it.
Methods are bound to a class, so "Calling Object" is redundant as Aaron points out.
Usually I think of "the Caller" as some code or object outside of the bound method.
Say I have a form called form1 and I create a instance of Puppy. From form1 I called p.bark(). I would see the Calling object is form1.
I don't think there is a 100% correct answer here.
-
"Usually I think of 'the caller' as some code or object outside of the bound method." Exactly. To me, the "caller" is the scope within which the method is called.ybakos– ybakos11/17/2011 02:01:45Commented Nov 17, 2011 at 2:01
p
was called or that the callee was called. Objects are never "called" nor do they "call" per se.main()
. Since your title question asks for a name for the "calling object", it's interesting that you chose to callp.bark()
from a function that doesn't belong to any class. Given that, could you restate your question so that we can figure out what you're really asking about?