Live longer than the application, should endure restarts, and are persisted and read from data sources (DB, file system, network, etc.)
Have an id (preferably a GUID rather than a DB generated int because business transactions do not rely on persistence, can be persisted after other operations carried out in model's behavior)
import { BaseDomainEntity, Entity, UniqueEntityID, Result} from'types-ddd';interfaceCarPropsextendsBaseDomainEntity { year:CarYearValueObject; color:CarColorValueObject;}classCarextendsEntity<CarProps> {privateconstructor(props:CarProps) {super (props,Car.name) }getyear ():CarYearValueObject {returnthis.props.year; }setYear (year:number):void {this.props.year = year; }getcolor ():CarColorValueObject {returnthis.props.color; }setColor (color:CarColorValueObject):void {this.props.color = color; }publicstaticisValidYear (year:number):boolean {return year >1920; }publicstaticcreate (props:CarProps):Result<Car> {// Business logic validation. Just for example!// Some rules should be validated on the value objectif (!Car.isValidYear(props.year.value)) {returnResult.fail<Car>('Invalid year for a car'); }returnResult.ok<Car>(newCar(props)); }}constcar=Car.create({ ... }).getResult();