Page 1 of 1 |
|
Posted: Thu, 5th Jun 2014 15:59 Post subject: Instance of an object and the object itself. |
|
 |
I just want to clarify my understanding here.
say we have a class Human.
Human H1 = new Human();
H1 is the instance that refers to that particular Human object.
Is the object Human before H1 or new Human();
|
|
Back to top |
|
 |
|
Posted: Thu, 5th Jun 2014 16:09 Post subject: |
|
 |
Human is a class.
H1 is a fresh object of type Human.
Human H1 says that you are going to define an object called H1, that is of type Human. Then you define it with the = new Human(); So it will go through the constructor of your class and initialize a fresh human with whatever is defined in there.
|
|
Back to top |
|
 |
|
Posted: Thu, 5th Jun 2014 16:17 Post subject: |
|
 |
so, essentially:
if we had a constructor of (string name, int age)
Human (type) H1 (object) = new Human ("Rayne", 30); that is a particular instance of an object of type Human.
Without the name and age inserted its simply an object, once the information has been set, the object then becomes an instance of the object of type Human?
|
|
Back to top |
|
 |
|
|
Back to top |
|
 |
Werelds
Special Little Man
Posts: 15098
Location: 0100111001001100
|
|
Back to top |
|
 |
|
|
Back to top |
|
 |
Werelds
Special Little Man
Posts: 15098
Location: 0100111001001100
|
Posted: Thu, 5th Jun 2014 18:58 Post subject: |
|
 |
That's the thing, an instance isn't anything
My first sentence makes that abundantly clear; we all use the word "instance" the same way, but semantically speaking it's incorrect
You can't swap any of those 3 words around and still have that sentence make sense. An instance isn't an object of a class. Nor is a class an instance of an object. Or an instance a class of an object. And so on 
|
|
Back to top |
|
 |
|
|
Back to top |
|
 |
Werelds
Special Little Man
Posts: 15098
Location: 0100111001001100
|
Posted: Thu, 5th Jun 2014 19:48 Post subject: |
|
 |
Quote: | This is a rather pointless debate though  |
Yes
But:
MinderMast wrote: | I guess when one speaks of an instance in terms of OOP, it's always implied to be an instance of some class, not an instance as some standalone construct, so I don't think it's incorrect to do so even from a semantic point of view.
I mean, whenever you say you are using an instance (although I doubt anyone often uses that word in a conversation ) it is implied to be an instance of something. |
That's exactly what I'm saying. We say we're using an instance but what we mean is an object that is an instance of a class 
|
|
Back to top |
|
 |
|
Posted: Thu, 5th Jun 2014 20:39 Post subject: |
|
 |
You are going to scare OP off. After reading all that he may "Meh, fuck it all. Will better work at McDonald's" 
|
|
Back to top |
|
 |
Werelds
Special Little Man
Posts: 15098
Location: 0100111001001100
|
Posted: Thu, 5th Jun 2014 20:50 Post subject: |
|
 |
Haha
Well the short answer to his question is just that from a practical point of view, an object and instance are the same thing.
|
|
Back to top |
|
 |
|
|
Back to top |
|
 |
|
Posted: Thu, 5th Jun 2014 23:54 Post subject: |
|
 |
The above was very well presented and gave me a clear indication of my problem, so, in short, an instance of type and an object of type is one in the same thing (instance of an object), essentially?
|
|
Back to top |
|
 |
|
|
Back to top |
|
 |
Page 1 of 1 |
All times are GMT + 1 Hour |