Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
Yehonathan Sharvit edited this pageApr 13, 2021 ·5 revisions

Identity (a.k.a Object, Entity)

Definition

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

At a given point in time, thestate 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 withShip 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 anatom.

(defjohn (atomnil))(defjohn-state-on-march-2021     {:age42: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 anatom
  3. The map with the fieldsage=42,firstName="John" andlastName="Doe" is a value
  4. After calling(reset! john ...), the state of the identity referred by the namejohn is the map with the fieldsage=42,firstName="John" andlastName="Doe".

See also

State,Value

Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp