"Object instance"

  • Thread starter Thread starter Piotr Perak
  • Start date Start date
P

Piotr Perak

Can someone explain the "object instance" term that is used i many of C#
books? I have C++ background. In C++ instance and object meant the same. I
could say that I have object of some class or instance of some class.
There was no object instance used. How can I understand object instance?
(I don't mean framweork class named object)
 
hi piotr,
Can someone explain the "object instance" term that is used i many of C#
books? I have C++ background. In C++ instance and object meant the same.
I could say that I have object of some class or instance of some class.
There was no object instance used. How can I understand object instance?
(I don't mean framweork class named object)

go for "instances" and forget about the syntactic sugar.
some authors uses "object" as a synonyme for "class".

C++: MyClass *c = new MyClass();
C#: MyClass c = new MyClass();

both "c" are instances of classes.

however, the memory allocation of instances is different:

C++: MyClass c = MyClass(); // stack-allocated,
// can go out of scope
C++: MyClass *c = new MyClass(); // heap-allocated

C#: MyClass c = new MyClass(); // like heap-allocated, but
// garbage-collected

bye
rob
 
hi piotr,

go for "instances" and forget about the syntactic sugar.
some authors uses "object" as a synonyme for "class".
But is it correct? We have big arguement on polish c# list. One of us say
that object and instance is the same, and others say that class is object.
But how could class ba an object? Here's how I understand it. Class is
only idea for object. I have to use new to create object(instance) of that
class.
C++: MyClass *c = new MyClass();
C#: MyClass c = new MyClass();

both "c" are instances of classes.
but in books I see c is "object instance". I don't get it. Maybe because
of not good enough knowing of english. For me it could be object instance
only if i did:
object o = new object();
like a d would be instance of Dog if I did:
Dog d = new Dog();
 
Piotr said:
But is it correct? We have big arguement on polish c# list. One of us
say that object and instance is the same, and others say that class is
object. But how could class ba an object? Here's how I understand it.
Class is only idea for object. I have to use new to create
object(instance) of that class.

do you want to speak to your compiler? he'll probably
not understand you, because he uses to understand
context-free grammars only! :-)

- classes are definitions
- objects are instances of classes
- "object instances" are redundant instances of classes.

bye
rob
 
Piotr,

It's just an effort to distance discussions from the common confusion
between "class" and "object". Many people have gotten sloppy in their use
of terminology and it clouds discussion with inaccuracies. Saying
"instance" instead of "object" emphasizes that you *really* mean the runtime
instance and not the design-time class. "Object" by itself is good I think,
but "object instance" is redunant and probably not helpful.

--Bob
 
Piotr,

It's just an effort to distance discussions from the common confusion
between "class" and "object". Many people have gotten sloppy in their
use
of terminology and it clouds discussion with inaccuracies. Saying
"instance" instead of "object" emphasizes that you *really* mean the
runtime
instance and not the design-time class. "Object" by itself is good I

But some people say that in C# class can also be called object. I say no,
but they say that's because I have C++ background where class is not
called an object. In C#, they say, different to C++, class IS an object.
Please tell me they wrong :)
but "object instance" is redunant and probably not helpful.
But is it correct? I can't get it. For me instance and object is the same.
Ofcourse we talk about programming.
 
Back
Top