Primary keys, IDs, references. The first attribute we add to our objects. They don’t exist in the real world.
- Accidental Implementation
- Bijection Principle Violation.
- Reference object to objects.
- Build a MAPPER.
- Only use keys if you need to provide an external (accidental) reference. Databases, APIs, Serializations.
- Use dark keys or GUIDs when possible.
- If you are afraid of getting a big relation graph use proxies or lazy loading.
- Don’t use DTOs.
This is a design policy.
We can enforce business objects to warn us if we define an attribute or function including the sequence id.
Ids are not necessary for OOP. You reference objects (essential) and never ids (accidental).
In case you need to provide a reference out of your system’s scope (APIs, interfaces, Serializations) use dark and meaningless IDs (GUIDs).
What is (wrong with) software?
Software is eating the world. Those of us who work, live and love software do not usually stop by to think about its…
All problems in computer science can be solved by another level of indirection.
This article is part of the CodeSmell Series.