Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

object and instance

 
Mike Yu
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can someone tell me what are the differences between instance and object?
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An instance of a class is an object.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Instance" is a more general concept.
As written above, an instance of a class is an object.
An instance of an association is a link (that is, between classes you have associations, between objects you have links).
An instance of a DTD or XML-Schema is an XML-file.
Does that help?
 
Mike Yu
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Thomas and Ilja,
Your answes are useful. I am still not very clear about the instance and object of EJB. It seems they have some diiferent meaning.
For Entity Bean, the application server creates instance, but it is assigned to an remote object only after the create method in the home interface is called.
Does someone have some ideas about the instance in this case?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mike Yu:
For Entity Bean, the application server creates instance, but it is assigned to an remote object only after the create method in the home interface is called.

The instance they are speaking of is the object that is instanciated by the application server - the actual entity bean. The remote object is an instance of the remote interface.
Does that make things clearer for you?
 
Mike Yu
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is much better! Thank you, Ilja.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Their meanings are very close so if you are having trouble differentiating them, its ok.
An object is created from a class. Many objects may be created from the same class. Each of these objects will be referred to as "instances" of that class.
So an object is always an instance, and an instance is always an object.
ClassA refA = new ClassA();
ClassA refA2 = new ClassA();
ClassB refB = new ClassB();
ClassB refB2 = new ClassB();
refA,refA2,refB,refB2 refer to objects;
refA,refA2 refer to instances of ClassA;
refB,refB2 refer to instances of ClassB;
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic