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: 93 KiB |
+1
-1
@@ -4,7 +4,7 @@
|
||||
|
||||
把一个类接口转换成另一个用户需要的接口。
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/3d5b828e-5c4d-48d8-a440-281e4a8e1c92.png"/> </div><br>
|
||||
<div align="center"> <img src="pics/adapter-turkey.png" width="740px"/> </div><br>
|
||||
|
||||
### Class Diagram
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="740" height="230" viewBox="0 0 740 230">
|
||||
<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">适配器:让火鸡冒充鸭子</text>
|
||||
<rect x="30" y="80" width="130" height="44" rx="6" fill="#EAE9E7" stroke="#BFBEBA"/>
|
||||
<text x="95" y="106.5" class="c sub b">客户端</text>
|
||||
<text x="95" y="146" class="c sub">只认 Duck 接口</text>
|
||||
<line x1="162" y1="102" x2="236" y2="102" class="arrow "/>
|
||||
<text x="199" y="94" class="c sub mono" style="fill:#444">quack()</text>
|
||||
<rect x="240" y="70" width="200" height="64" rx="4" fill="#C6ECE9" stroke="#7DBCB7"/>
|
||||
<text x="340" y="88" class="c sub b" style="fill:#444">TurkeyAdapter</text>
|
||||
<line x1="240" y1="96" x2="440" y2="96" stroke="#7DBCB7"/>
|
||||
<text x="248" y="112" class="sub mono" style="fill:#444">implements Duck</text>
|
||||
<text x="248" y="130" class="sub mono" style="fill:#444">quack() → gobble()</text>
|
||||
<line x1="442" y1="102" x2="516" y2="102" class="arrow "/>
|
||||
<text x="479" y="94" class="c sub mono" style="fill:#444">gobble()</text>
|
||||
<rect x="520" y="76" width="180" height="46" rx="4" fill="#C6E4FB" stroke="#7FB2D6"/>
|
||||
<text x="610" y="94" class="c sub b" style="fill:#444">WildTurkey</text>
|
||||
<line x1="520" y1="102" x2="700" y2="102" stroke="#7FB2D6"/>
|
||||
<text x="528" y="118" class="sub mono" style="fill:#444">gobble()</text>
|
||||
<text x="610" y="150" class="c sub mono">输出 gobble!</text>
|
||||
<text x="30" y="210" class="sub">适配器实现客户端需要的接口,内部持有被适配的对象,把调用转换过去;两边的代码都不用修改。</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.0 KiB |
Reference in New Issue
Block a user