-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
53 lines (44 loc) · 1.15 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class Order {
private _id: number;
private _clientName: ClientName;
private _value: number;
private _date: Date;
constructor(id: number, clientName: ClientName, value: number) {
this._id = id;
this._clientName = clientName;
this._value = value;
this._date = new Date();
}
}
class ClientName {
private readonly _firstName: string;
private readonly _lastName: string;
constructor(firstName: string, lastName: string) {
if (!this.isValidName(firstName)) {
throw new Error('firstName is required');
}
this._firstName = firstName;
if (!this.isValidName(lastName)) {
throw new Error('lastName is required');
}
this._lastName = lastName;
}
private isValidName(name: string) {
return !!name;
}
get first(): string {
return this._firstName;
}
get last(): string {
return this._lastName;
}
get full(): string {
return `${this._firstName} ${this._lastName}`;
}
}
const clientName = new ClientName('Israel', 'Borba');
console.log(clientName.first);
console.log(clientName.last);
console.log(clientName.full);
const order = new Order(1, clientName, 100);
console.log(order);