2

I have code like the following in my main():

myObject.doSomething()

Now, i know that doSomething() is called as method.

I want to know what myObject can be technically named in this context.

First, I thought it could be called as caller; but then I thought that in common knowledge, the function from the which the call is made is called the caller - here main. So what do I call myObject here?

Naman Gala
  • 4,670
  • 1
  • 21
  • 55
tomol
  • 755
  • 1
  • 6
  • 12
  • 1
    Looks like the doSomething() is a static method in the class MyObject – DSF Apr 08 '15 at 06:31
  • 1
    possible duplicate of [Equivalent term for 'receiver' in languages not Objective-C](http://stackoverflow.com/questions/4584578/equivalent-term-for-receiver-in-languages-not-objective-c) (Note - Objective-C calls it the "receiver") – Krease Apr 08 '15 at 06:36
  • @DSF Not a static method. An instance method that has side effects on `MyObject` – tomol Apr 08 '15 at 06:39
  • 1
    Then 'MyObject ' is an instance object :) – DSF Apr 08 '15 at 06:41
  • @DSF changed to `myObject`. I have been doing `C` and only `C` for many years. I need to know what it's called from the method's perspective... something like a `caller` – tomol Apr 08 '15 at 06:41
  • You should get yourself used to the java coding style. You can find a pretty nice guide here: https://google-styleguide.googlecode.com/svn/trunk/javaguide.html – DSF Apr 08 '15 at 06:43
  • You can refer this [question](http://stackoverflow.com/questions/1215881/the-difference-between-classes-objects-and-instances) (Possible duplication). – Naman Gala Apr 08 '15 at 06:45

4 Answers4

3

Older terminology is "the receiver". This was from the beginning of OOP, when it had to have a name so that it could be explained to (then) non-OOP programmers. Nowadays, everyone learns OOP first and there isn't a need for a terminology.

Atsby
  • 2,277
  • 12
  • 14
3

MyObject is the class name. This is your blueprint. This is the type you will use to create "objects".

What are objects?

Objects are instances of the class type you declared. In more concrete terms:

I can declare something like that:

class Shape{
    int x;
    int y;
}

When I do something like that:

Shape circle = new Shape();

circle is an instance based on the blueprint i.e the class Shape.

Think of the class as an idea, what the architect drew. The new operator is the civil engineer who just built the building, an instance of the architect's blueprint.

Ralph
  • 2,959
  • 9
  • 26
  • 49
  • But it's still an *instance* in any context; I thought OP's question was about terminology specific to method invocation. I.e., "what is to instance as argument is to expression?" if I may put it in the form of an analogy. – Atsby Apr 08 '15 at 06:48
1

instance maybe? the fact that the method belongs to the object instance and called by it, is supposed to be already included in the concept of object method, since no-one else can call an object's methods but itself

Nikos M.
  • 8,033
  • 4
  • 36
  • 43
1

First of all the m should be small :P.

myObject.doSomething() --> here, myObject is an instance of class MyClass. That's what it should be called - instance of class X.

TheLostMind
  • 35,966
  • 12
  • 68
  • 104