什么时候使用Bridge Pattern?如何与适配器模式不同? [英] When do you use the Bridge Pattern? How is it different from Adapter pattern?

查看:141
本文介绍了什么时候使用Bridge Pattern?如何与适配器模式不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人曾经在现实世界的应用中使用过 Bridge Pattern ?如果是这样,你是怎么使用的?是我,还是只是适配器图案,一点点依赖注入投入混合?它真的值得自己的模式吗?

Has anyone ever used the Bridge Pattern in a real world application? If so, how did you use it? Is it me, or is it just the Adaptor Pattern with a little dependancy injection thrown into the mix? Does it really deserve its own pattern?

推荐答案

Bridge模式的一个典型例子用于UI中形状定义环境(参见 Bridge pattern Wikipedia entry )。 Bridge模式是复合的<一个href =http://en.wikipedia.org/wiki/Template_method_pattern =noreferrer>模板和策略模式。

A classic example of the Bridge pattern is used in the definition of shapes in an UI environment (see the Bridge pattern Wikipedia entry). The Bridge pattern is a composite of the Template and Strategy patterns.

这是Bridge模式中适配器模式的一些常见视图。但是,要引用这篇文章

It is a common view some aspects of the Adapter pattern in the Bridge pattern. However, to quote from this article:


首先看到,Bridge模式看起来很像Adapter模式,因为类用于将一种界面转换为另一种。然而,适配器模式的目的是使一个或多个类的接口看起来与特定类的接口相同。 Bridge模式旨在将类的界面与其实现分开,以便您可以在不更改客户端代码的情况下更改或替换实现。

At first sight, the Bridge pattern looks a lot like the Adapter pattern in that a class is used to convert one kind of interface to another. However, the intent of the Adapter pattern is to make one or more classes' interfaces look the same as that of a particular class. The Bridge pattern is designed to separate a class's interface from its implementation so you can vary or replace the implementation without changing the client code.

这篇关于什么时候使用Bridge Pattern?如何与适配器模式不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆