Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Identity (object-oriented programming)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{multiple issues| {{unreferenced|date=March 2016}} {{original research|date=March 2016}} }} In [[object-oriented programming]], [[object-oriented analysis and design|analysis and design]], [[object (computer science)|object]] '''identity''' is the fundamental property of every object that it is distinct from other objects. Objects have identity {{endash}} are distinct {{endash}} even when they are otherwise indistinguishable, i.e. [[Equality (mathematics)|equal]]. In this way, object identity is closely related to the [[identity (philosophy)|philosophical meaning]]. == Identity and references == A [[reference (computer science)|reference]] 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 language]], and allows access to the object with the identity. A type of a target of a reference is a role. Typically, references are isomorphic to memory addresses. However, multiple such references can refer to the same object, if some form of address mapping is present ([[Virtual memory|virtual addresses]] / [[page tables]] / [[Memory segmentation|memory segments]]). Object identity is less useful as a semantic concept in environments or situations in which the structure of objects is not encapsulated, and two objects are considered to be the same object based on having identical properties, even if they are not actually the same physical instance (structural equivalence). However, object identity can nevertheless provide optimization. A function which tests whether two arguments are the same object can quickly short circuit to an affirmative answer if the two arguments have the same identity (are references to the same instance). Only if the argument are distinct objects do the individual properties need to be considered to determine equality, which is a more expensive operation. For instance, [[bignum]] integers may be heap-allocated objects such that two bignums are considered to be the same if they represent the same number. It might be a waste of machine cycles in the equality function not to take advantage of the discovery that the two arguments being compared are references to the same bignum. == Consequences of identity == Identity of objects allows objects to be treated as [[Black box (systems)|black box]]es. 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 [[ontology (information science)|ontology]] or conceptual model, that is often used as basis of object-oriented thinking. The conceptual model describes the [[client (computing)|client]] side view to a [[application domain|domain]], terminology or an [[application programming interface|API]]. This world contains point-like objects as [[instance (computer science)|instances]], properties of the objects and links between those objects. The objects in the world can be grouped to form [[class (computer science)|class]]es. The properties of the objects can be grouped to form [[role (object-oriented programming)|role]]s. The links can be grouped to form [[association (object-oriented programming)|association]]s. All locations in the world together with the links between the locations form the structure of the world. These groups are [[datatype|type]]s of the corresponding instances of the world. <!-- == References == {{reflist}} --> == See also == * {{Annotated link|Domain-driven design}} * {{Annotated link|Object-Oriented Software Construction}} * {{webarchive |url=https://web.archive.org/web/20080515223645/http://www.cs.cmu.edu/People/clamen/OODBMS/Manifesto/htManifesto/node4.html |date=15 May 2008 |title=Object identity}} [[Category:Object-oriented programming]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Annotated link
(
edit
)
Template:Endash
(
edit
)
Template:Multiple issues
(
edit
)
Template:Webarchive
(
edit
)