3

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.

ybakos
  • 297

6 Answers6

8

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.

Aaron McIver
  • 3,262
3

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.

Caleb
  • 39,298
1

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).

Demian Brecht
  • 17,585
1

I'd go with any of:

  • call target
  • method owner (although this doesn't really make sense if p is null, because then it hardly owns anything)
  • callee

Although in that very context, I'd go with p ;)

back2dos
  • 30,140
0

I'd generally call p an instance of Puppy, not the calling object

Wyatt Barnett
  • 20,787
0

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.

Jon Raynor
  • 11,773