关闭

Design pattern learning I: Facade pattern

987人阅读 评论(0) 收藏 举报

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. 学习或维护原系统的代价要比创建新的接口类大

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:28271次
    • 积分:423
    • 等级:
    • 排名:千里之外
    • 原创:14篇
    • 转载:1篇
    • 译文:1篇
    • 评论:8条
    最新评论