File tree Expand file tree Collapse file tree 3 files changed +15
-15
lines changed Expand file tree Collapse file tree 3 files changed +15
-15
lines changed Original file line number Diff line number Diff line change 4
4
5
5
示例中把主板单中的启动(start)方法和重启(reboot)方法封装为命令对象,再传递到主机(box)对象中。于两个按钮进行绑定:
6
6
7
- * 第一个机箱(box1)设置按钮1(buttion1 ) 为开机按钮2(buttion2 )为重启。
8
- * 第二个机箱(box1)设置按钮2(buttion2 ) 为开机按钮1(buttion1 )为重启。
7
+ * 第一个机箱(box1)设置按钮1(button1 ) 为开机按钮2(button2 )为重启。
8
+ * 第二个机箱(box1)设置按钮2(button2 ) 为开机按钮1(button1 )为重启。
9
9
10
10
从而得到配置灵活性。
11
11
Original file line number Diff line number Diff line change @@ -45,21 +45,21 @@ func (*MotherBoard) Reboot() {
45
45
}
46
46
47
47
type Box struct {
48
- buttion1 Command
49
- buttion2 Command
48
+ button1 Command
49
+ button2 Command
50
50
}
51
51
52
- func NewBox (buttion1 , buttion2 Command ) * Box {
52
+ func NewBox (button1 , button2 Command ) * Box {
53
53
return & Box {
54
- buttion1 : buttion1 ,
55
- buttion2 : buttion2 ,
54
+ button1 : button1 ,
55
+ button2 : button2 ,
56
56
}
57
57
}
58
58
59
- func (b * Box ) PressButtion1 () {
60
- b .buttion1 .Execute ()
59
+ func (b * Box ) PressButton1 () {
60
+ b .button1 .Execute ()
61
61
}
62
62
63
- func (b * Box ) PressButtion2 () {
64
- b .buttion2 .Execute ()
63
+ func (b * Box ) PressButton2 () {
64
+ b .button2 .Execute ()
65
65
}
Original file line number Diff line number Diff line change @@ -6,12 +6,12 @@ func ExampleCommand() {
6
6
rebootCommand := NewRebootCommand (mb )
7
7
8
8
box1 := NewBox (startCommand , rebootCommand )
9
- box1 .PressButtion1 ()
10
- box1 .PressButtion2 ()
9
+ box1 .PressButton1 ()
10
+ box1 .PressButton2 ()
11
11
12
12
box2 := NewBox (rebootCommand , startCommand )
13
- box2 .PressButtion1 ()
14
- box2 .PressButtion2 ()
13
+ box2 .PressButton1 ()
14
+ box2 .PressButton2 ()
15
15
// Output:
16
16
// system starting
17
17
// system rebooting
You can’t perform that action at this time.
0 commit comments