This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Domain { | |
export class Hero { | |
private constructor(private _name: string) { } | |
get name(): string { return this._name; } | |
static create(name: string): [Hero, Error] { | |
if (!name || name.trim().length < 3 || name.trim().length > 100) { | |
return [null, new InvalidNameError(name)] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Value object | |
class CityName { | |
static readonly MIN_LEN_NAME: number = 3 | |
static readonly MAX_LEN_NAME: number = 100 | |
private constructor(private _name: string) { } | |
// Factory method with validation rules | |
static create(name: string): [CityName, Error] { |