Abstract
Base class for Entities in Domain-Driven Design.
Entities are objects that have a distinct identity that runs through time and different representations. They are compared by their identity rather than their attributes.
class User extends Entity<'User'> { constructor( id: EntityId<'User'>, private email: string, private name: string ) { super(id, new Date(), new Date()); } changeName(newName: string): void { this.name = newName; this.touch(); // Update the updatedAt timestamp }} Copy
class User extends Entity<'User'> { constructor( id: EntityId<'User'>, private email: string, private name: string ) { super(id, new Date(), new Date()); } changeName(newName: string): void { this.name = newName; this.touch(); // Update the updatedAt timestamp }}
Phantom type representing the entity type (e.g., 'User', 'Order')
Gets the unique identifier of this entity.
Gets the timestamp when this entity was created.
Gets the timestamp when this entity was last updated.
Protected
Updates the updatedAt timestamp to the current time. Should be called whenever the entity's state changes.
Compares this entity with another for equality based on identity. Two entities are equal if they have the same ID and are of the same type.
The other entity to compare with
true if the entities are equal, false otherwise
Base class for Entities in Domain-Driven Design.
Entities are objects that have a distinct identity that runs through time and different representations. They are compared by their identity rather than their attributes.
Example