
Structural Pattern
发布日期:2021-05-08 06:01:06
浏览次数:18
分类:精选文章
本文共 958 字,大约阅读时间需要 3 分钟。
1. Adapter(Wrapper)
- Convert the interface of a class into another interface clients expect.
- 有时候一些工具类被设计为复用, 但是由于接口不匹配的问题不能够复用
- Adapter会为Adaptee(adapted class)增加一些没有的没有的功能, 用来与应用程序相适配.
- 实现方式:
- class composition(更加灵活 <- 多态性)
- multi-inheritance
- Pluggable adaptors
adapter向上展现的接口一致的 adapter向下调用的方式一致(通过函数对象\可调用对象\lambda表达式, 这些可以用括号调用的对象, 统称"函子(factor)")
2. Bridge Pattern (Handle/Body)
- Decouple an abstraction from ites implementation so that the two can vary independently
- 使用继承会使得类的数量大幅度增长, 而桥接模式可以使类的数量保持的比较少
3. Facade[fə'sɑːd] Pattern
- Provide a unified interface to a set of interface in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use
- 比如:
对于一个可以编译多种语言的编译器, 其底层的scanner, parser, codeGenerator等如何调用, 被compiler给统一起来,用户要编译源代码时,只要调用compile即可s
4. Composite Pattern
Compose objects into tree structures to represent part-whole hierarchies.
Composite lets clients treat individual objects and compositions of objects uniformly
发表评论
最新留言
关注你微信了!
[***.104.42.241]2025年04月12日 17时24分29秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
java接口中多继承的问题
2021-05-09
java中Object.equals()简单用法
2021-05-09
一个小例子对多态简单的理解
2021-05-09
poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)
2021-05-09
poj 2492A Bug's Life(并查集)
2021-05-09
ZZUOJ 1199 大小关系(拓扑排序,两种方法_判断入度和dfs回路判断)
2021-05-09
java中自动装箱的问题
2021-05-09
zyUpload+struct2完成文件上传
2021-05-09
knockout+echarts实现图表展示
2021-05-09
js冲刺一下
2021-05-09
程序员的开发文档
2021-05-09
mybatis generator修改默认生成的sql模板
2021-05-09