-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathAnimal.ts
More file actions
executable file
·45 lines (38 loc) · 1010 Bytes
/
Animal.ts
File metadata and controls
executable file
·45 lines (38 loc) · 1010 Bytes
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
export enum FoodChainType {
Carnivorous = 'carnivorous',
Herbivorous = 'herbivorous',
Omnivorous = 'omnivorous',
}
interface IAnimal {
name: string;
sound?: string;
family: string;
foodChainType: FoodChainType;
}
interface IBasicAnimal extends IAnimal{
whoAmI: () => void;
makeSound: () => void;
}
interface IAnimalConstructor extends IAnimal{
}
export class Animal implements IBasicAnimal {
public name: string;
public sound: string;
public family: string;
public foodChainType: FoodChainType;
constructor(params: IAnimalConstructor) {
this.name = params.name;
this.sound = params.sound || '';
this.family = params.family;
this.foodChainType = params.foodChainType;
}
public whoAmI(): void {
console.log(`I am a ${this.name}, my family is ${this.family}. My diet is ${this.foodChainType}.`);
if (this.sound) {
console.log([...Array(2).fill(this.sound)].join(', '));
}
}
public makeSound(): void {
console.log(this.sound);
}
}