Skip to content
Yehonathan Sharvit edited this page Apr 13, 2021 · 5 revisions

Identity (a.k.a Object, Entity)

Definition

An identity is a stable logical entity that humans or programs associate with a series of attributes attributes over time. An identity represents a thread of continuity, though its attributes may change.

At a given point in time, the state of an identity is the value of its attributes.

Most programs deal with identity. We might even claim that:

Programming is identity-oriented mathematics

Properties

Identities have state

At a given point in time, the state of an identity is the value of its attributes.

Identity state can be changed

Changing the state of an identity means changing the value of one or more of its attributes.

Identities can be shared

This is crucial to know whether an identity is shared or not. This is because a change made to the identity by one sharer will be visible to the other sharer.

An identity might be shared by:

  • Functions in the same thread
  • Threads in the same process
  • Processes in the same machine
  • Machines in the same cluster
  • Different Clusters

Identities can be created and destroyed

Equality between identities is not value-based

Two identities might have the exact same attribute values and be different.

A single identity might have different attribute values at two different points in time.

Compare with Ship of Theseus.

Examples

Traditional OOP

In traditional OOP (e.g. Java, C#, C++) , we usually represent an identity with an object.

The problem with this approach is that we don't have access to the state of the object (the aggregated values of all its attributes) outside the context of the object. We can only access an attribute of the object (via member fields).

Clojure's atom

In Clojure, we usually represent an identity with an atom.

(def john (atom nil))

(def john-state-on-march-2021
     {:age 42  
      :firstName "John"
      :lastName "Doe"})
  
(reset! john john-state-on-march-2021)

Let's describe exactly what happens in this code snippet in terms of name, identity, state and value:

  1. john is a name that refers to an identity
  2. The identity is represented as an atom
  3. The map with the fields age=42, firstName="John" and lastName="Doe" is a value
  4. After calling (reset! john ...), the state of the identity referred by the name john is the map with the fields age=42, firstName="John" and lastName="Doe".

See also

State, Value

Clone this wiki locally