I found this answer to be the most appealing. :)
I dealt with this issue in a lot of applications and there are several
facts that are just difficult to discuss "away":
* There will be a lookup from different use cases based on an unique
identifier. This identifier should probably not be a domain-related
thing because than you couple your domain attributes directly to your
persistence mechanisms. And since object instances are highly transient
(and kind of an implementation detail) they are just not suitable to
determine identity.
* Identifiers are the only commonality between the inherently different
worlds of "serialized data rows" and "object instances in memory".
So I strive for a semantic decoupling of the generation of the UID from
the actual persistence. Vernon suggests this approach of exposing a
service in your domain that can give you a new UID for a new entity of a
specific kind (e.g.: `userAuthority.nextUid()`). If this service is
given as an interface suddenly a lot of possibilities arise. A simple
approach would be using UUID or an incrementing integer as a first naive
implementation. A more advanced approach could be implemented by using
the physical persistence layer to implement a persisted counter that is
used to generate unique UIDs.
Anyway the point is that this approach moves the generation of unique
identity away from the actually persisting layer towards the core of
your domain where it is way more flexible.
Since I use this approach a lot of problems with (otherwise artificially
complex feeling) identity management have just vanished.
WDYT?
Cheers
Jakob
On 09/11/2014 01:09 AM, Michel Henrich wrote:
> There's an kind of an unspoken rule nowadays that all entities should have a unique ID independently of any attributes that it may have. This allows for greater flexibility, for instance, if you want to allow your users to change their username or e-mail (like facebook does). Also it simplifies the way the application deals with entity identification by having a "pattern" to follow (like always having a UUID). If I remember correctly, the fuss was only because of the usage of UUID, which UB is clearly against - which makes me wonder if they will change to something else later.
>
--
Jakob Holderbaum, M.Sc.
Systems Engineer
0176 637 297 71
http://jakob.io
h...@jakob.io
@hldrbm