-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathtemplate.ats
60 lines (49 loc) · 1.51 KB
/
template.ats
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
import { Logger } from '../logger';
export class HouseTemplate {
constructor() {
this.logger = new Logger();
}
//Template method, final so subclasses can't override
buildHouse() {
this.buildFoundation();
this.buildPillars();
this.buildWalls();
this.buildWindows();
this.logger.log("House is built.");
this.logger.log("***************");
}
//Always same for all kinds of concrete classes so it is implemented in base.
buildFoundation() {
this.logger.log("Building foundation with cement,iron rods and sand");
}
//Always same for all kinds of concrete classes so it is implemented in base.
buildWindows() {
this.logger.log("Building glass windows");
}
//Abstract method which is to be implemented in concrete classes
buildPillars() {
throw new Error("Abstract Method!");
}
//Abstract method which is to be implemented in concrete classes
buildWalls() {
throw new Error("Abstract Method!");
}
}
//Concrete implementor 1/2
export class WoodenHouse extends HouseTemplate {
buildWalls() {
this.logger.log("Building wooden walls.");
}
buildPillars() {
this.logger.log("Building pillars with wooden coating.");
}
}
//Concrete implementor 2/2
export class GlassHouse extends HouseTemplate {
buildWalls() {
this.logger.log("Building glass walls.");
}
buildPillars() {
this.logger.log("Building pillars with glass coating.");
}
}