-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabstractFactory.ts
64 lines (55 loc) · 1014 Bytes
/
abstractFactory.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
54
55
56
57
58
59
60
61
62
63
64
interface IChair {
getNozhki(): number;
}
interface ITable {
getArea(): number;
}
class ChairA implements IChair {
getNozhki() {
return 2;
}
}
class TableA implements ITable {
getArea() {
return 2;
}
}
class ChairB implements IChair {
getNozhki() {
return 4;
}
}
class TableB implements ITable {
getArea() {
return 4;
}
}
abstract class FactoryM {
abstract createChair(): IChair;
abstract createTable(): ITable;
}
class FactoryA extends FactoryM {
createChair(): ChairA {
return new ChairA();
}
createTable(): TableA {
return new TableA();
}
}
class FactoryB extends FactoryM {
createChair(): ChairB {
return new ChairB();
}
createTable(): TableB {
return new TableB();
}
}
class AppM {
private typeFactory!: FactoryM;
createFactory() {
this.typeFactory = new FactoryA();
}
createChair() {
this.typeFactory.createChair();
}
}