C++/object and instance?
Expert: Prince M. Premnath - 11/6/2006
QuestionHi,
when should we user the word "object", and when the word "instance"?
Thanks,
lzzzz
AnswerDear lzzzz !
The term object means a combination of data and logic that represent some real world entity ,
eg:
Consider BMW cars . The BMW can be represented in a computer program as an 'object' , in which the data part of the BMW object is the car's name , color , price , and so on.
Class defnition differentiate one object from other but in fact a class is a set of objects that share a commnon structure and common behaviour , a signle object is simply an instance of a class.
A real-world example of an object would be "BMW-M5", which is an instance of a type (a class) called "BMW", which is a subclass of a class "CARS".
In the case of a polymorphic object, some details of its type can be selectively ignored,
for example a "BMW" object could be used by a function looking for an "CARS". So could a "LIMO", because it too belongs to the class of "CARS".
While being accessed as an "CARS", some member attributes of a "BMW-M5" or "LIMO" would remain unavailable, such as the "ROOF" attribute, because some cars may not have roof !
Regards !
Prince M. Premnath