HOME

TheInfoList



OR:

In
object-oriented programming Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of ...
,
object-oriented design Object-oriented design (OOD) is the process of planning a Object-oriented programming, system of interacting objects for the purpose of solving a software problem. It is one approach to software design. Overview An Object (computer science), obje ...
and object-oriented analysis, the identity of an
object Object may refer to: General meanings * Object (philosophy), a thing, being, or concept ** Object (abstract), an object which does not exist at any particular time or place ** Physical object, an identifiable collection of matter * Goal, an ...
is its being distinct from any other object, regardless of the values of the objects' properties. Having identity is a fundamental property of objects. This is closely related to the philosophical concept of
identity Identity may refer to: * Identity document * Identity (philosophy) * Identity (social science) * Identity (mathematics) Arts and entertainment Film and television * ''Identity'' (1987 film), an Iranian film * ''Identity'' (2003 film), an ...
.


Identity and references

A
reference Reference is a relationship between objects in which one object designates, or acts as a means by which to connect to or link to, another object. The first object in this relation is said to ''refer to'' the second object. It is called a '' name'' ...
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 A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language. The description of a programming ...
, 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 addresses / page tables / 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 In science, computing, and engineering, a black box is a system which can be viewed in terms of its inputs and outputs (or transfer characteristics), without any knowledge of its internal workings. Its implementation is "opaque" (black). The te ...
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 In programming language theory and type theory, polymorphism is the provision of a single interface to entities of different types or the use of a single symbol to represent multiple different types.: "Polymorphic types are types whose operati ...
. 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 In metaphysics, ontology is the philosophy, philosophical study of being, as well as related concepts such as existence, Becoming (philosophy), becoming, and reality. Ontology addresses questions like how entities are grouped into Category ...
or conceptual model, that is often used as basis of object-oriented thinking. The conceptual model describes the
client Client(s) or The Client may refer to: * Client (business) * Client (computing), hardware or software that accesses a remote service on another computer * Customer or client, a recipient of goods or services in return for monetary or other valuabl ...
side view to a
domain Domain may refer to: Mathematics *Domain of a function, the set of input values for which the (total) function is defined ** Domain of definition of a partial function ** Natural domain of a partial function **Domain of holomorphy of a function * ...
, terminology or an API. 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
class Class or The Class may refer to: Common uses not otherwise categorized * Class (biology), a taxonomic rank * Class (knowledge representation), a collection of individuals or objects * Class (philosophy), an analytical concept used differently ...
es. The properties of the objects can be grouped to form
role A role (also rĂ´le or social role) is a set of connected behaviors, rights, moral obligation, obligations, beliefs, and social norm, norms as conceptualized by people in a social situation. It is an expected or free or continuously changing behavi ...
s. The links can be grouped to form associations. 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.


Notes


See also

* Meyer: Object-oriented software construction, second edition * {{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 *
Domain-driven design Domain-driven design (DDD) is a major software design approach, focusing on modeling software to match a domain according to input from that domain's experts. Under domain-driven design, the structure and language of software code (class names ...
: An entity is defined by identity Object-oriented programming