mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-10-29 07:03:43 +00:00
Update 设计模式 - 命令.md
重新绘制配图。
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 132 KiB |
+1
-1
@@ -22,7 +22,7 @@
|
||||
|
||||
设计一个遥控器,可以控制电灯开关。
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/e6bded8e-41a0-489a-88a6-638e88ab7666.jpg"/> </div><br>
|
||||
<div align="center"> <img src="pics/command-remote.png" width="740px"/> </div><br>
|
||||
|
||||
```java
|
||||
public interface Command {
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="740" height="300" viewBox="0 0 740 300">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.sub { font-size: 11px; fill: #6E6E6E; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #555; stroke-width: 1.1; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #DADADA; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="370" y="28" class="title">命令:遥控器只认 Command 接口</text>
|
||||
<rect x="30" y="56" width="200" height="190" rx="8" class="frame"/>
|
||||
<text x="40" y="74" class="b">Invoker(遥控器)</text>
|
||||
<rect x="46" y="90" width="70" height="28" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="81" y="108" class="c sub mono" style="fill:#444">on[0]</text>
|
||||
<rect x="130" y="90" width="80" height="28" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="170" y="108" class="c sub mono" style="fill:#444">off[0]</text>
|
||||
<rect x="46" y="126" width="70" height="28" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="81" y="144" class="c sub mono" style="fill:#444">on[1]</text>
|
||||
<rect x="130" y="126" width="80" height="28" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="170" y="144" class="c sub mono" style="fill:#444">off[1]</text>
|
||||
<rect x="46" y="162" width="70" height="28" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="81" y="180" class="c sub mono" style="fill:#444">on[2]</text>
|
||||
<rect x="130" y="162" width="80" height="28" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="170" y="180" class="c sub mono" style="fill:#444">off[2]</text>
|
||||
<rect x="46" y="198" width="70" height="28" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="81" y="216" class="c sub mono" style="fill:#444">on[3]</text>
|
||||
<rect x="130" y="198" width="80" height="28" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="170" y="216" class="c sub mono" style="fill:#444">off[3]</text>
|
||||
<rect x="300" y="70" width="190" height="46" rx="4" fill="#C6ECE9" stroke="#7DBCB7"/>
|
||||
<text x="395" y="88" class="c sub b" style="fill:#444">LightOnCommand</text>
|
||||
<line x1="300" y1="96" x2="490" y2="96" stroke="#7DBCB7"/>
|
||||
<text x="308" y="112" class="sub mono" style="fill:#444">execute() { light.on(); }</text>
|
||||
<rect x="300" y="160" width="190" height="46" rx="4" fill="#C6ECE9" stroke="#7DBCB7"/>
|
||||
<text x="395" y="178" class="c sub b" style="fill:#444">LightOffCommand</text>
|
||||
<line x1="300" y1="186" x2="490" y2="186" stroke="#7DBCB7"/>
|
||||
<text x="308" y="202" class="sub mono" style="fill:#444">execute() { light.off(); }</text>
|
||||
<rect x="560" y="110" width="150" height="64" rx="4" fill="#EAE9E7" stroke="#BFBEBA"/>
|
||||
<text x="635" y="128" class="c sub b" style="fill:#444">Light(接收者)</text>
|
||||
<line x1="560" y1="136" x2="710" y2="136" stroke="#BFBEBA"/>
|
||||
<text x="568" y="152" class="sub mono" style="fill:#444">on()</text>
|
||||
<text x="568" y="170" class="sub mono" style="fill:#444">off()</text>
|
||||
<path d="M81,88 C81,62 250,62 296,88" class="arrow"/>
|
||||
<line x1="212" y1="104" x2="296" y2="186" class="arrow "/>
|
||||
<line x1="492" y1="100" x2="556" y2="136" class="arrow "/>
|
||||
<line x1="492" y1="190" x2="556" y2="160" class="arrow "/>
|
||||
<text x="208" y="70" class="sub"></text>
|
||||
<text x="30" y="270" class="sub">onButtonWasPushed(0) 只调用 onCommands[0].execute(),不知道背后是电灯还是空调;换一个命令对象,按钮就有了新功能。</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.6 KiB |
Reference in New Issue
Block a user