Class ValueObjectAbstract

Base class for Value Objects in Domain-Driven Design.

Value Objects are immutable objects that represent descriptive aspects of the domain with no conceptual identity. They are compared by their structural content rather than identity.

class Email extends ValueObject {
constructor(private readonly value: string) {
super();
}

protected getEqualityComponents(): unknown[] {
return [this.value];
}
}

const email1 = new Email('user@example.com');
const email2 = new Email('user@example.com');
console.log(email1.equals(email2)); // true

Hierarchy (View Summary)

Constructors

Methods

  • Returns the components that determine equality for this Value Object. Two Value Objects are equal if all their equality components are equal.

    Returns unknown[]

    An array of values used for equality comparison

  • Compares this Value Object with another for equality. Value Objects are equal if they are of the same type and all equality components match.

    Parameters

    • other: ValueObject

      The other Value Object to compare with

    Returns boolean

    true if the Value Objects are equal, false otherwise