当前位置: 首页 > 工具软件 > Pattern-lab > 使用案例 >

Design pattern learning I: Facade pattern

蒯卓君
2023-12-01

Gang of Four says: Provide a unified interface to a set of interfaces in subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.

Facade pattern enables us to use a complex system more easily, either to use just a subset of the system in a particular way.

Facade can be used not only to create a simpler interface in terms of method calls, but also reduce the number of objects that a client object must deal with.

Facade pattern applies when:
1. You don't need to use all of the functionality of a complex system and can create a new class that contains all of the rules for accessing that system.
2. You want to encapsulate or hide the orignial system.
3. You want to use the functionality of the original system and want to add some new functionality as well.
4. The cost of writing this new class is less than the cost of everybody learning how to use the original system or is less then you would spend on maintenance in the future.


GOF说:
Facade模式在子系统的接口集上提供了统一的对外接口。Facade定义了一个高层的接口使得子系统更容易被使用。

定义:
Facade模式使得我们更容易使用一个复杂系统,或者通过特殊方式使用系统的一个子集。它不仅能用来创建一个简单的接口,也减少了客户必须交互的对象数量。

可以把Facade应用在:
1. 你不想使用复杂系统的所有功能,并创建一个新的类来包含所有的访问系统的规则
2. 你想封装或者隐藏原系统
3. 你想使用原系统的功能,也想添加新的功能
4. 学习或维护原系统的代价要比创建新的接口类大

 类似资料:

相关阅读

相关文章

相关问答