Choosing Fields for Object Equality

A value object can define equality using the fields representing its meaning. Identity remains relevant when it represents a particular persistent entity.

Source
Anbloq
Language
English
Created
Updated
Chapters
2
Reading time
1 min
In this article2 chapters
  1. Compare coordinates and accounts
  2. Keep keys stable

Compare coordinates and accounts

Two separately constructed points at (2, 7) can compare equal by coordinate. Two accounts with the same display label can still represent different entities. Record equality explains this domain choice.

Keep keys stable

If objects participate in hash lookups, changes to equality-relevant fields can make lookups unreliable. Preserve the required hash and equality relationship for the lifetime of a stored key.[1]

References

  1. Python Software Foundation, Python Tutorial: Classes ↩