Livin' Virtual World

Game develop, Programming & Fun

Design pattern learning I: Facade pattern

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

阅读更多
上一篇Dead Reckoning: 在网络游戏中消除延时影响
下一篇Design pattern learning II: Adapter pattern
想对作者说点什么? 我来说一句

GOF设计模式中文版(Design Pattern

2011年04月10日 10.11MB 下载

Design*Pattern*Framework*4.5

2016年09月24日 45.97MB 下载

没有更多推荐了,返回首页

关闭
关闭