Identity in software design
Uniqueness, sameness, relative identity, and sortals offer a clearer mental model for guiding the design decisions involved.
Software designers frequently face the challenge of maintaining the identity of software entities over time, and I've always been looking for a mental model to guide the design decisions involved. Despite how common this challenge is, I've yet to find a thorough discussion on the topic, even after reading several software design books.
Recently, I found some intriguing insights by looking into the etymology of identity and the philosophical debates around it.
The word stems from the Latin identitas, meaning sameness or the quality of being identical. Over time, its meaning evolved through Medieval Latin, Old French, and English to include uniqueness.
Identity is about defining uniqueness and sameness.
Philosophical debates about identity have been ongoing since ancient times, with more structured discussions emerging in the early modern period. In the 20th century, these debates shifted from the concept of absolute identity to relative identity, offering new perspectives that resonate with software design.
In 1967, philosopher Peter Geach introduced the concept of relative identity, suggesting that identity depends on the type of thing being compared. In other words, two entities can be identical in one way but different in another.
This idea is particularly useful in software design, where we often ask: a is the same what as b? The key is determining the what on which the identity is based, referred to by Geach as the Sortal.
Identity in software design is relative, based on a specific criterion or Sortal that determines both uniqueness and sameness.
Sortals act as labels for types of software entities and predicates for determining identity.
Different types of software entities have their Sortals:
For reference types, the Sortal is the memory location, with uniqueness defined by a distinct memory address and sameness by reference equality.
For value types, the Sortal is the content, with uniqueness defined by the content itself and sameness by value equality. Examples include primitives, structs, and Value Objects.
For entity types, the Sortal is the unique identifier, with uniqueness defined by the identifier itself and sameness by the value equality of those identifiers. Example includes Reference Objects or Entities.
For behavior types, the Sortal is behavior, with uniqueness defined by interfaces, protocols, and contracts, and sameness by the consistent fulfillment of those contracts.
These distinct types serve different roles in software design. Reference types are crucial for system-level concerns like memory management, concurrency, and polymorphism. Value, entity, and behavior types help developers model domains. Entity types are suited for mutable concepts, value types for immutables, and behavior types for defining contracts that enable polymorphism and decoupling.
By framing identity in terms of uniqueness and sameness, and applying the ideas of relative identity and Sortal, we gain a clearer mental model to guide our design decisions in maintaining software entity identity over time. This approach also helps clarify design patterns like Value Objects and Entities in Domain-Driven Design (DDD), making the learning curve a little less steep.