1. Adapter(Wrapper)
- Convert the interface of a class into another interface clients expect.
- 有时候一些工具类被设计为复用, 但是由于接口不匹配的问题不能够复用
- Adapter会为Adaptee(adapted class)增加一些没有的没有的功能, 用来与应用程序相适配.
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