知识卡片
适配器屏蔽第三方库
适配器可把第三方Element接口包装成业务ActionNode,向客户提供动作名、类名、方法名及结果视图,集中转换约定并减少库类型泄漏。它不能消除数据语义与库行为的全部影响。
原getMethodName未处理缺省属性,基类默认还误写excuete;getView(result)却固定创建success访问者,忽略参数。需要按领域契约正确转换,不能因加包装就宣称换库无需影响其他代码。图按真实接口与包装关系,未运行。
结构图:
classDiagram
class ActionNode {
<<abstract>>
+getActionName() String
+getActionClass() String
+getMethodName() String
+getView(String result) String
}
class XmlActionNode {
-Element el
+XmlActionNode(Element el)
+getActionName() String
+getActionClass() String
+getMethodName() String
+getView(String result) String
}
class Element {
<<interface>>
+attribute(String name) Attribute
+accept(Visitor visitor) void
}
ActionNode <|-- XmlActionNode
XmlActionNode o--> Element : 包装库接口
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 第37章 MVC框架 · 查看原书依据
public class XmlActionNode extends ActionNode { //需要转换的element private Element el; //通过构造函数传递 public XmlActionNode(Element _el){ t
参考来源
- 位置:《设计模式之禅(第2版)》第37章 MVC框架(来源项目book-sources,源文件:extracted/设计模式之禅(第2版)/_epub-src/text/part0158.html)
- 结论依据:原文定义、示例及取舍支撑本卡;已知过强表述在正文限定。
- 原始内容:public class XmlActionNode extends ActionNode { //需要转换的element private Element el; //通过构造函数传递 public XmlActionNode(Element _el){ t