diff --git a/notes/pics/adapter-turkey.png b/notes/pics/adapter-turkey.png new file mode 100644 index 00000000..dcc5f8b8 Binary files /dev/null and b/notes/pics/adapter-turkey.png differ diff --git a/notes/设计模式 - 适配器.md b/notes/设计模式 - 适配器.md index 72eb98cd..f2d14a7e 100644 --- a/notes/设计模式 - 适配器.md +++ b/notes/设计模式 - 适配器.md @@ -4,7 +4,7 @@ 把一个类接口转换成另一个用户需要的接口。 -

+

### Class Diagram diff --git a/tools/diagram/src/adapter-turkey.svg b/tools/diagram/src/adapter-turkey.svg new file mode 100644 index 00000000..91d93d1c --- /dev/null +++ b/tools/diagram/src/adapter-turkey.svg @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + 适配器:让火鸡冒充鸭子 + + 客户端 + 只认 Duck 接口 + + quack() + + TurkeyAdapter + + implements Duck + quack() → gobble() + + gobble() + + WildTurkey + + gobble() + 输出 gobble! + 适配器实现客户端需要的接口,内部持有被适配的对象,把调用转换过去;两边的代码都不用修改。 +