UNPKG

deepsource-mcp-server

Version:
56 lines (55 loc) 1.51 kB
/** * @fileoverview Base entity class for domain-driven design * * This module provides the base class for all entities in the domain layer. * Entities are domain objects that have a unique identity that persists * throughout their lifecycle, even as their attributes change. */ /** * Base class for all entities in the domain * * Entities are distinguished by their identity rather than their attributes. * Two entities with the same attributes but different identities are considered different. * * @example * ```typescript * class User extends Entity<string> { * constructor( * id: string, * private _name: string, * private _email: string * ) { * super(id); * } * * get name(): string { * return this._name; * } * * changeName(name: string): void { * if (!name || name.length === 0) { * throw new Error('Name cannot be empty'); * } * this._name = name; * } * } * ``` */ export declare abstract class Entity<TId> { protected readonly _id: TId; protected constructor(id: TId); /** * Gets the unique identifier of the entity */ get id(): TId; /** * Checks equality between two entities * * Two entities are equal if they have the same identity, * regardless of their other attributes. * * @param other - The entity to compare with * @returns True if the entities have the same identity, false otherwise */ equals(other: Entity<TId>): boolean; }