12 | 类与接口的关系

class-interface.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
interface Human {
// new (name: string): void;
name: string;
eat(): void;
}

class Asian implements Human {
constructor(name:string){
this.name = name;
}
name: string;
eat(){};
sleep(){}
}

interface Man extends Human{
run(): void;
}

interface Child {
cry():void;
}

interface Boy extends Man, Child{}

let boy: Boy = {
name: '',
run(){},
eat(){},
cry(){}
}

class Auto {
state = 1
// private state2 = 0
}
interface AutoInterface extends Auto{

}
class C implements AutoInterface{
state = 1
}

class Bus extends Auto implements AutoInterface{

}
  • 下图为class与interface的关系图

class与interface的关系图

要是这篇文章帮到了您,期待您请我喝一杯咖啡。