-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFactoryMethod.dart
64 lines (53 loc) · 1.44 KB
/
FactoryMethod.dart
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
import 'package:design_pattern_dart/Display/Example.dart';
class FactoryMethod extends Example {
FactoryMethod([String filePath = "lib/Creational/FactoryMethod.dart"])
: super(filePath);
@override
String testRun() {
var devManager = DevelopmentManager();
var makManager = MarketingManager();
return """
// Create a development manager.
${devManager.takeInterview()}
// Create a marketing manager.
${makManager.takeInterview()}
""";
}
}
// 面試可以有「社群經營」的、可以有「開發」方面的
abstract class Interviewer {
String askQuestions();
}
class CommunityExecutive extends Interviewer {
@override
String askQuestions() {
return 'What is Community Building ?';
}
}
class Developer extends Interviewer {
@override
String askQuestions() {
return 'What is Design Pattern ?';
}
}
// Manager 可以是開發面試官、可以是社群經營面試官,但都屬於 HiringManager
// 兩者都可以直接使用 takeInterview() 的函式
abstract class HiringManager {
Interviewer _makeInterviewer();
String takeInterview() {
var interviewer = _makeInterviewer();
return interviewer.askQuestions();
}
}
class DevelopmentManager extends HiringManager {
@override
Interviewer _makeInterviewer() {
return Developer();
}
}
class MarketingManager extends HiringManager {
@override
Interviewer _makeInterviewer() {
return CommunityExecutive();
}
}