white-label icon indicating copy to clipboard operation
white-label copied to clipboard

What is the difference between id & userId?

Open amirh715 opened this issue 5 years ago • 1 comments

export class User extends AggregateRoot<UserProps> {

    get id (): UniqueEntityID {
        return this._id;
    }

    get userId (): UserId {
        return UserId.caller(this.id);
    }

    get email (): UserEmail {
        return this.props.email;
    }
        .
        .
        .
}

Why are there two id attributes in class User? one is named id and the other userId. Why not use id : UniqueEntityID for all aggregates? Also, the Function.caller seems to be deprecated.

amirh715 avatar Sep 19 '20 12:09 amirh715

The ID identifies that unique entity in this moment and it's always an UUID,

You do not use this as UserID for a few possible reasons ( You can, but you force your design to this ):

  • Force your User domain entity to have an UUID as ID, so you won't be able to use a DB generated ID
  • You force the Value object of your Domain entity
  • In this model the way of working with UniqueEntityID Is not the same rather than working with Entity props

You can, of course you can but your force your domain model to work this way. The way that UniqueEntityID is build for.

Remember that is your have constraints for your domain model, in terms of identity that in your question, will be handled by UniqueEntityID class, you will have to modify this one, doing this you will be modifiying all the rest of ID's that well, for 1 function this won't be a big problem but in the long term that class, being used this way could have a big chance to become a big ball of mud.

InfoLorenzo avatar Mar 15 '22 17:03 InfoLorenzo