-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSimpleFactory.dart
More file actions
42 lines (34 loc) · 869 Bytes
/
SimpleFactory.dart
File metadata and controls
42 lines (34 loc) · 869 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
import 'package:design_pattern_dart/Display/Example.dart';
class SimpleFactory extends Example {
SimpleFactory([String filePath = "lib/Creational/SimpleFactory.dart"])
: super(filePath);
@override
String testRun() {
var door1 = DoorFactory.createDoor(100, 200);
var door2 = DoorFactory.createDoor(50, 100);
return """
door1's width =
${door1.width}
door2's height =
${door2.height}
""";
}
}
// 想想門應該要有什麼屬性
abstract class Door {
double width;
double height;
Door(this.width, this.height);
}
// 木門有門的各種屬性
class WoodenDoor implements Door {
double height;
double width;
WoodenDoor(this.width, this.height);
}
// 建立一個工廠生產門
class DoorFactory {
static Door createDoor(double width, double height) {
return WoodenDoor(width, height);
}
}