forked from hazukac/DesignPatterns
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMain.java
More file actions
83 lines (66 loc) · 2.68 KB
/
Copy pathMain.java
File metadata and controls
83 lines (66 loc) · 2.68 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import framework.*;
public class Main {
private static final char strongerDeco = '~';
public static void main(String[] args) {
// 登録
bootstrap();
// なんかするん
someOperation1("strong message");
someOperation2("simple box");
}
public static void bootstrap() {
Manager manager = Manager.getMng();
// {{{
UnderlinePen ulpen = new UnderlinePen('~');
MessageBox mb = new MessageBox('#');
MessageBox simpleBox = new MessageBox('*');
manager.register("strong message", ulpen);
manager.register("congrats message", mb);
manager.register("simple box", simpleBox);
// }}}
}
public static void someOperation1(String method) {
Manager manager = Manager.getMng();
Product p1 = manager.create(method);
p1.use("Hello, World!");
/*
UnderlinePen ul = new UnderlinePen(strongerDeco);
ul.use("Hello, World!");
*/
Product p2 = manager.create("congrats message");
p2.use("田井中律誕生日おめでとう(あした)");
Product p3 = manager.create("simple box");
p3.use("hazukac");
}
public static void someOperation2(String method) {
Manager manager = Manager.getMng();
Product p1 = manager.create(method);
p1.use("Hello, World!");
/*
UnderlinePen ul = new UnderlinePen(strongerDeco);
ul.use("Hello, World!");
*/
Product p2 = manager.create("congrats message");
p2.use("平沢唯誕生日おめでとう 11/01");
Product p3 = manager.create("simple box");
p3.use("hazukac");
}
// コンパイル時に決定できない要素を取るようなインスタンス化が必要なクラス
// は、registerを使わないと、再現できない?
// めちゃくちゃ多い暮らす定義(*, /, (, &, %, ...) を管理したいのであれば
// コンストラクタに * etcを取るクラスを用意してそれをnewすればいいのではないか
// <-
// newの箇所が100カ所だと、* -> / という要件が発生したとき
// 100カ所直すじゃん
// <-
// public decochar = '*' -> '/'
// <-
// コンストラクタに渡す要素が、'*'だけじゃなかった場合、つらい
// (1)
// 事前把握できてるけれど、糞めんどい
// (2)
// 事前把握できないインスタンス化をしなきゃいけないとき
// manager.register(time.Now().ToString(), instanceOfNow);
// (3)
// クラス名がわからない、クラス名を気にしないクラス名をつくりたいとき
}