An
identity in
object-oriented programmingObject-oriented programming is a programming paradigm that uses "objects" – data structures consisting of datafields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as information hiding, data...
, object-oriented design and object-oriented analysis describes the property of
objectIn computer science, an object, in the domain of object-oriented programming, usually means a compilation of attributes and behaviors encapsulating an entity....
s that distinguishes them from other objects. This is closely related to the philosophical concept of
identityIn philosophy, identity is whatever makes an entity definable and recognizable, in terms of possessing a set of qualities or characteristics that distinguish it from entities of a different type...
.
A
referenceIn computer science, a reference is a value that enables a program to directly access a particular data item, such as a variable or a record, in the computer's memory or in some other storage device. The reference is said to refer to the data item, and accessing that data is called dereferencing...
can be used to refer to an object with a specific identity. A reference contains the information that is necessary for the identity property to be realized in the
programming languageA programming language is an artificial language designed to express computations that can be performed by a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine, to express algorithms precisely, or as a mode of human...
, and allows access to the object with the identity.
An
identity in
object-oriented programmingObject-oriented programming is a programming paradigm that uses "objects" – data structures consisting of datafields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as information hiding, data...
, object-oriented design and object-oriented analysis describes the property of
objectIn computer science, an object, in the domain of object-oriented programming, usually means a compilation of attributes and behaviors encapsulating an entity....
s that distinguishes them from other objects. This is closely related to the philosophical concept of
identityIn philosophy, identity is whatever makes an entity definable and recognizable, in terms of possessing a set of qualities or characteristics that distinguish it from entities of a different type...
.
Identity and references
A
referenceIn computer science, a reference is a value that enables a program to directly access a particular data item, such as a variable or a record, in the computer's memory or in some other storage device. The reference is said to refer to the data item, and accessing that data is called dereferencing...
can be used to refer to an object with a specific identity. A reference contains the information that is necessary for the identity property to be realized in the
programming languageA programming language is an artificial language designed to express computations that can be performed by a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine, to express algorithms precisely, or as a mode of human...
, and allows access to the object with the identity. A type of a target of a reference is a role.
Object identity is often not useful, if referential transparency is assumed, because identity is a property that an object may contain, aspects that are not visible in its interface. Thus, objects need to be identified in the interface with a mechanism that is distinct from the methods used to access the object's state in its interface. With referential transparency, the value of the state of the object would be identical or isomorphic with the values accessible from the object's interface. There would be no difference between the object's interface and its implementation, and the identity property would provide no useful additional information.
Identity and location
Identity is closely associated with the locations that objects are stored in. Some programming languages implement object identity by using the location of the object in computer memory as the mechanism for realizing object identity. However, objects can move from one place to another without change to their identity, and can be stored in places other than computer memory, so this does not fully characterize object identity.
This distinction is well illustrated in the case of
live distributed objects- Definitions :The term live distributed object refers to a running instance of a distributed multi-party protocol, viewed from the object-oriented perspective, as an entity that has a distinct identity, may encapsulate internal state and threads of execution, and that exhibits a well-defined...
, defined as instances of distributed multi-party protocols viewed from the object-oriented perspective. A distributed protocol instance, such as a multicast group or a publish-subscribe topic, does not exist in a single location; it typically spans across a set of machines distributed over the network, which can change as the machines join and leave the protocol instance. Nevertheless, it can still be viewed as a single object, as it has a well-defined identity, state and externally-visible behavior. In this case, the identity is determined by the same factors that distinguish between different protocol instances; these might include the description of a peer-to-peer protocol running between object replicas, including all essential parameters, such as the identifier of the multicast group or a publish-subscribe channel, or the identity of the services that maintains the membership. Thus, while identity and location are closely connected concepts, they are, in fact, not the same.
Consequences of identity
Identity of objects allows objects to be treated as black boxes. The object need not expose its internal structure. It can still be referred to, and its other properties can be accessed via its external behaviour associated with the identity. The identity provides a mechanism for referring to such parts of the object that are not exposed in the interface. Thus, identity is the basis for polymorphism in object-oriented programming.
Identity allows comparison of references. Two references can be compared whether they are equal or not. Due to the identity property, this comparison has special properties. If the comparison of references indicates that the references are equal, then it's clear that the two objects pointed by the references are the same object. If the references do not compare equal, then it's not necessarily guaranteed that the identity of the objects behind those references is different. The object identity of two objects of the same type is the same, if every change to either object is also a change to the other object.
Identity and object-oriented conceptual model
Identity allows the construction of a platonic ideal world, the
ontologyIn computer science and information science, an ontology is a formal representation of a set of concepts within a domain and the relationships between those concepts. It is used to reason about the properties of that domain, and may be used to define the domain.In theory, an ontology is a "formal,...
or conceptual model, that is often used as basis of object-oriented thinking. The conceptual model describes the
clientA client is an application or system that accesses a remote service on another computer system, known as a server, by way of a network. The term was first applied to devices that were not capable of running their own stand-alone programs, but could interact with remote computers via a network...
side view to a
domainA domain in software engineering is a set of related software systems that share common design features. Domains in this contexthave been defined as:*An application area*A business area*A software business area*A software intensive application area...
, terminology or an
APIAn application programming interface is an interface in computer science that defines the ways by which an application program may request services from libraries and/or operating systems. An API determines the vocabulary and calling conventions the programmer should employ to use the services...
. This world contains point-like objects as instances, properties of the objects and links between those objects. The objects in the world can be grouped to form
classIn object-oriented programming, a class is a construct that is used as a blueprint to create objects of that class. This blueprint describes the state and behavior that the objects of the class all share. An object of a given class is called an instance of the class. The class that contains that...
es. The properties of the objects can be grouped to form roles. The links can be grouped to form
associationIn object-oriented programming, association defines a relationship between classes of objects which allows one object instance to cause another to perform an action on its behalf...
s. All locations in the world together with the links between the locations form the structure of the world. These groups are types of the corresponding instances of the world.
See also
- Meyer: Object-oriented software construction, second edition
- http://www.cs.cmu.edu/People/clamen/OODBMS/Manifesto/htManifesto/node4.html