lec5_Bridge-汉语软件设计模式.ppt

  1. 1、本文档共58页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Lecture 4 Bridge Pattern 本讲内容 桥接模式的引入 桥接模式理论 使用桥接模式进行设计的例子 Introductory Examples 例1: 科学家宇航员的设计例子 优点: 在两个维度上可以自由地添加类,而不会影响 到其它的类。 例2: 咖啡销售机软件设计例子 New design: In classes MediumCoffee or SuperSizeCoffee, call MilkCoffeeImp or FragrantCoffeeImp 设计3优点: 可以在两个维度上可以自由地添 加新类,而不会影响到其它的类 桥模式的构件 (Participants) Abstraction defines the abstraction's interface. maintains a reference to an object of type Implementor. RefinedAbstraction Extends the interface defined by Abstraction. Implementor Defines the interface for implementation classes. This interface doesn't have to correspond exactly to Abstraction's interface; in fact the two interfaces can be quite different. Typically The Implementor interface provides only primitive operations, and The Abstraction defines higher-level operations based on these primitives. The ConcreteImplementors: ImplementorA and ImplementorB implements the Implementor interface and defines its concrete implementation. 桥模式的优点 将接口与实现解耦。Decoupling interface and implementation. An implementation is not bound permanently to an interface The implementation of an abstraction can be configured at run-time Decoupling Abstraction and Implementor also eliminates compile-time dependencies on the implementation Changing an implementation class doesn't require recompiling the Abstraction class and its clients 2. 改善了可扩展性。Improved extensibility. You can extend the Abstraction and Implementor hierarchies independently. 3. 对用户隐藏实现细节。Hiding implementation details from clients. You can shield clients from implementation details, like the sharing of implementor objects and the accompanying reference count mechanism (if any). 何时使用桥模式? When to use the bridge pattern? Applicability: Use the Bridge pattern when you want to avoid a permanent binding between an abstraction and its implementation. e. g. when the implementation must be selected or switched at run-time. More advantages of Bridge Pattern Both the

文档评论(0)

东山书苑 + 关注
实名认证
内容提供者

业务以学生学习成长为中心,为外语培训、中小学基础教育、学前教育,提供各种学习资料支持服务。

1亿VIP精品文档

相关文档