user3143218
user3143218

Reputation: 1816

What's the correct terminology when referring to an instance?

There's lots of questions here on objects, classes, instances, instantiation etc... But I can't find the answer to my question. I'm trying to write some documentation and having trouble finding the correct terminology to use.

There's a good answer here that's related, but not what I'm looking for here.

There's also some basic info over on Wikipedia here.

Consider the following (in the PHP realm although it may be the same for other languages) :

Let's say I have singleton class:

class fooBar
{
    protected static $instance;

    private function __construct() {
    }

    public static function getInstance()
    {
        if(self::$instance === null) {
            self::$instance = new fooBar;
        }
        return self::$instance;
    }
}

I then instantiate the class:

$foo = fooBar::getInstance();

Later on in my code I use the getInstance method to get a reference:

$bar = fooBar::getInstance();

So when I'm referring to $bar, what is the correct terminology:

  1. $bar is a reference to the fooBar class instance.
  2. $bar is a reference to a fooBar class instance.
  3. $bar is the fooBar class instance.
  4. $bar returns a reference to the fooBar class instance.
  5. $bar returns the fooBar class instance.
  6. $bar returns a fooBar class instance.

Which of these is correct (if any) ?

Lastly, when referring to the already instantiated fooBar class in general do I refer to it as "The fooBar instance"?

Upvotes: 1

Views: 71

Answers (1)

Ihor Burlachenko
Ihor Burlachenko

Reputation: 4905

It is a variable which holds fooBar class singleton instance. Since objects in PHP are passed by reference it is the same as fooBar class singleton instance. I would say go with option 3), everybody will understand you. Options 4)-6) are simply incorrect and 1) looks overcomplicated for me.

Upvotes: 1

Related Questions