Science Fair Project Encyclopedia
Object (computer science)
An object is a data structure that is unique and separate from other objects, although they are able to interact with other objects.
- data members that represent the data associated with the object.
- methods that access the data members in predefined ways.
In the case of most objects, one can access the data members only through the method members, making it easy to guarantee that the data will always remain in a well-defined state (class invariants will be enforced). Some languages do not make distinctions between data members and methods.
A real-world example of an object would be "my dog", which is an instance of a type (a class) called "dog", which is a subclass of a class "animal". In the case of a polymorphic object, some details of its type can be selectively ignored, for example a "dog" object could be used by a function looking for an "animal". So could a "cat", because it too belongs to the class of "animal". While being accessed as an "animal", some member attributes of a "dog" or "cat" would remain unavailable, such as the "tail" attribute, because not all animals have tails.
Three properties characterize objects:
- identity - the property of an object that distinguishes it from other objects
- state - describes the data stored in the object
- behaviour - describes the methods in the object's interface by which the object can be used
Some terms for specialized kinds of objects include:
- Singleton object - An object that will only allow itself to be instantiated once during the lifetime of the program.
- Functor (function object) - an object with a single method (in C++, this method would be the function operator, "operator()") that acts much like a function (like a C/C++ pointer to a function).
- Immutable object - an object set up with a fixed state at creation time and which does not vary afterward.
- First-class object - an object that can be used without restriction.
- Container object - an object that can contain other objects.
- Factory object - an object that can create other objects.
The contents of this article is licensed from www.wikipedia.org under the GNU Free Documentation License. Click here to see the transparent copy and copyright details