桥梁模式(Bridge)
桥梁模式属于结构类的设计模式,示意结构图如下:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAosAAAEBCAIAAACfS3hjAAAgAElEQVR4nO2dLYzdxtvFjaL+WeALl1gKXBhgEFhYs8KVTAoLDMqCrMISS4UBBoWRUaFhyUiBlVGYAwsMAucFp/fpk/HYO/fD9qzv+YHVXV9/PHd8Zs58eZxYQgghhMRHsncAhBBCCPFAhyaEEEJihA5NCCGExAgdmhBCCIkROjQhhBASI3RoQgghJEbo0IQQQkiM0KEJIYSQGKFDE0IIITFChyaEEEJihA5NCCGExAgdmhBCCIkROjQhhBASI3RoQgghJEbo0IQQQkiM0KEJIYSQGKFDE0IIITFChyaEEEJihA5NCCGExAgdmhBCCIkROjQhhBASI1s79OPjY0JIkiRJ8vj4uLH8CCHkBbG1QycJW+3kXygGQghZgA5NdoNiIISQBejQZDcoBkIIWYAOTXaDYiCEkAXo0GQ3KAZCCFmADk12g2IghJAF6ND/MgxD3/d6S9u2ewWzzDAMe4dwG6IVAyGExAAd+l+yLCvLUv4tyzLLsh3jWSDLsjzP947iBkQrhgjhQgLkfuBKCQId2lprh2HIskxbsjHmLIfuus4Yc/PAiqKYbmzbtuu6m19re+IUQ5wwrcj9QLULdGhrrW2apqqqNE1ly7kOXRTF1KGv7I5eiGEcx2cPD9lnX+IUQ5wwrcj9QLULdGhrrS2KYhiGNE2lbQp3LMsyz/Msy2SIummaPM+xsaoq2ZKmKTqfm6bBCbMswwnxLUa127bNT2BPCcDZiEukaYrt2Nj3Pc6GSwvok8/zXLbjcJw2y7I4h67jFEOcMK3I/UC1C3Roa62FBRZFIUPRxpg0TdEsrutaPFIatV3XaZvMssxpQxtjkiTBCcuyhEPLOXF+uTpOpTfa+Ta0VA5AWZbyb1EU8Hgdv94hKuIUQ5wwrcj9QLULdOh/B6GrqkJzExu1O2rjTNO0LEtn1redcWhtt6Dve1g72sdyTmnj6pMEOrQ4sbW26zocoo/F5QJSYmsiFEO0MK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v+zRNZbkf8X581ulsT0ntrL6LpMDigtPL0aEJIWSBfRwaplhVFYwWBuk0bRdeyW5nXsM+d0iaprLcsZ2sja5fzKLPiZ11v7Fe4D7LMnEsHDX3drO5oe6Fl6jol8jOvT98zqFv++42/d4O2bhwa856jxAdmhBCFoioDT33ylI749DTz/pdvPrNP07rzel2Fqf0vtw0z3M0351Wr9cI67rGyb1vanPwvv7P+Vcf66SP97W7N5/4JtUm3VGxcNe0Q+s3als6NCGEnMmhHHqu+ehs7/veMWNY3ZxDh5zTnrx8+u1KDj0Mw/TNu/IiuRuC36XH3enQhBCyATs7tLaTkF5u/bLb6bf6zSr6zBcYvFiL86J46fF2zulMZ/M6tPNKwcBe7jmHfvZ3LRP+pr/pU2EX9HJ7p/vRoQkhZIG4Viyp61pmimkzw9QkecEqZnXJ1GsxZozC4rWp8HI90cx5QSwMT9telmW4OsKQnfM8x4tLZeAZF8Vr0mU3eDkOx/i6/grzqnQAmGKmp7/BpPUr6Ou6loZyWZbOPG39alWkUvj07LIsA58p7/veaawjKfBLpVYhM8V0UmOWHPaUt7sLdGhCCFkgLocGVz7RG364s6c8wbXGpVd6TFneeT4MwwZLr2guTmeBDk0IIQvE6NC7gHb5S3znvPQl7B3I2UQrBkIIiQE6NNkNioEQQhagQ5PdoBgIIWQBOjTZDYqBEEIWoEOT3aAYCCFkga2LSL6jjQhrvKyNEEIOAxsxhBBCSIzQoQkhhJAYoUMTQgghMUKHJoQQQmKEDk0IIYTECB2aEEIIiRE6NCGEEBIjdGhCCCEkRujQhBBCSIzQoQkhhJAYoUMTQgghMUKHJoQQQmKEDk0IIYTECB2aEEIIiRE6NCGEEBIjdGhCCCEkRujQhBBCSIzQoQkhhJAYoUMTQgghMUKHJoQQQmKEDk0IIYTEyP8DkgtguiFSAUAAAAAASUVORK5CYII=" alt="" />
桥梁模式所涉及的角色有:
● 抽象化(Abstraction)角色:抽象化给出的定义,并保存一个对实现化对象的引用。
● 修正抽象化(RefinedAbstraction)角色:扩展抽象化角色,改变和修正父类对抽象化的定义。
● 实现化(Implementor)角色:这个角色给出实现化角色的接口,但不给出具体的实现。必须指出的是,这个接口不一定和抽象化角色的接口定义相同,实际上,这两个接口可以非常不一样。实现化角色应当只给出底层操作,而抽象化角色应当只给出基于底层操作的更高一层的操作。
● 具体实现化(ConcreteImplementor)角色:这个角色给出实现化角色接口的具体实现。
关键点:
1、抽象化角色可以通过向不同的实现化对象委派达到动态转换自己的目的
2、抽象化角色和实现化角色之间是聚合关系,而不是继承关系
如果 一个类需要知道另一个类的属性和方法,可以选择继承,也可以选择组合(聚合),在使用组合时,则需要持有对方的引用
以一个万能遥控的例子说明该模式的应用:(为了在同一个文件共存,代码中类前面的public都省略了)
package designpatterns.strucural; //抽象角色--Abstraction
abstract class AbstractRemoteControl { protected ITV tv; public void bindImpl(ITV tv){
this.tv = tv;
} public void turnOn(){
tv.on();
} public void turnOff(){
tv.off();
} public void setChannel(int channel){
tv.switchChannel(channel);
}
}
//精确抽象角色--RefinedAbstraction
class PcRemoteControl extends AbstractRemoteControl { @Override
public void turnOn() {
System.out.println("Pc On");
}
} class CommonRemoteControl extends AbstractRemoteControl{ @Override
public void turnOn() {
super.turnOn();
} @Override
public void turnOff() {
super.turnOff();
} @Override
public void setChannel(int channel) {
super.setChannel(channel);
}
} //实现角色--mplementor
/*
* 首先定义电视机的接口:ITV*/
interface ITV { public void on();
public void off();
public void switchChannel(int channel);
}
//具体实现角色--ConcreteImplementor1
/*
* 再实现三星的ITV接口。*/
class SamsungTV implements ITV {
@Override
public void on() {
System.out.println("Samsung is turned on.");
} @Override
public void off() {
System.out.println("Samsung is turned off.");
} @Override
public void switchChannel(int channel) {
System.out.println("Samsung: channel - " + channel);
}
}
//具体实现角色--ConcreteImplementor2
/*
* 再实现索尼的ITV接口。*/
class SonyTV implements ITV { @Override
public void on() {
System.out.println("Sony is turned on.");
} @Override
public void off() {
System.out.println("Sony is turned off.");
} @Override
public void switchChannel(int channel) {
System.out.println("Sony: channel - " + channel);
}
} //测试类
public class Bridge {
public static void main(String[] args){
ITV tv1 = new SonyTV();
ITV tv2 = new SamsungTV(); AbstractRemoteControl control = new CommonRemoteControl();
control.bindImpl(tv1);
control.turnOn();
control.bindImpl(tv2);
control.turnOn(); AbstractRemoteControl control_pc = new PcRemoteControl();
control_pc.turnOn();
}
}
验证输出:
Sony is turned on.
Samsung is turned on.
Pc On
代码说明:
抽象化角色:远程控制,通过持有ITV接口实例,达到对电视万能控制
修正抽象化角色:pc的远程控制,有朝一日,电视消失了,证明抽象化角色还可以复用
实现化角色:ITV ,这个可以定义为抽象类,也可以定义为接口,个人倾向定义为接口,毕竟代码量少
具体实现化角色:各品牌的电视
何时持有对方引用?
阎宏博士java与模式一书省略了这一点,不少博客的例子是通过构造函数传参的方式获取对方引用,也许是为了图省事儿
我觉得恰是这些省略让人不太好体会这个模式的特点,因为这么干就说不清楚和抽象工厂模式的区别了,像下面的代码
Animal A = new cat()
A.run()
Animal B = new dog()
B.run()
持有对方引用通过调用一个普通方法
public void bindImpl(ITV tv){
this.tv = tv;
}
这样就只需要有一个实例,通过绑定不同的实现化对象,达到动态转换自己功能
类似于现实中,你有一个万能遥控器,通过点击某个电视品牌,你就能实现对具体电视的控制
参考:
桥梁模式(Bridge)的更多相关文章
- 桥接模式 桥梁模式 bridge 结构型 设计模式(十二)
桥接模式Bridge Bridge 意为桥梁,桥接模式的作用就像桥梁一样,用于把两件事物连接起来 意图 将抽象部分与他的实现部分进行分离,使得他们都可以独立的发展. 意图解析 依赖倒置原 ...
- 说说设计模式~桥梁模式(Bridge)
返回目录 在软件系统中,某些类型由于自身的逻辑,它具有两个或多个维度的变化,那么如何应对这种“多维度的变化”?如何利用面向对象的技术来使得该类型能够轻松的沿着多个方向进行变化,而又不引入额外的复杂度? ...
- java设计模式之桥梁模式(Bridge)
1.桥梁模式 与 策略模式 非常相似 (其实很多设计模式都相似,因为所有的模式都是按照设计原则 而设计出来的,设计原则就相当于武功的心法,设计模式就是招式,只要心法过硬,就可以无招胜有招了.) 这里也 ...
- 变脸不变质的桥梁模式(Bridge Pattern)
有一哥们是搞山寨货的,什么流行就搞什么.自己有个厂子,前些时间服装挣钱,就生产衣服,如今搞手机挣钱,搞手机,这哥们非常聪明,就换了个产品,工人,厂房都不变.他是怎么做到的?用类图来模拟一下: 由类图能 ...
- 桥梁模式(Bridge Pattern)
桥梁模式是对象的结构模式.又称为柄体(Handle and Body)模式或接口(Interface)模式.桥梁模式的用意是“将抽象化(Abstraction)与实现化(Implementation) ...
- 24种设计模式--桥梁模式【Bridge Pattern】
今天我要说说我自己,梦想中的我自己,我身价过亿,有两个大公司,一个是房地产公司,一个是服装制造业,这两个公司都很赚钱,天天帮我在累加财富,其实是什么公司我倒是不关心,我关心的是是不是在赚钱,赚了多少, ...
- 设计模式C++学习笔记之十一(Bridge桥梁模式)
桥梁模式,将抽象部分与它的实现部分分离,使它们都可以独立地变化.实现分离的办法就是增加一个类, 11.1.解释 main(),客户 IProduct,产品接口 CHouse,房子 CIPod,ip ...
- 代理(Proxy)模式 ,桥梁(Bridge)模式
一:代理模式 1 根据名字我们就可以理解为:代替别人管理 2 什么情况下使用代理模式呢? 在软件系统中,有些对象有时候由于跨越网络或者其他的障碍,而不能够或者不想直接访问另一个对象,如果直接访问会给系 ...
- Java设计模式(13)——结构型模式之桥梁模式(Bridge)
一.概述 概念 将抽象与实现脱耦,使得抽象和实现可以独立运行 UML图 角色: 角色关系 二.实践 按照上面的角色建立相应的类 抽象化角色 /** * 抽象化角色 * * @author Admini ...
随机推荐
- Docker技术-cgroup
分类: 虚拟化 Docker容器采用了linux内核中的cgroup技术来实现container的资源的隔离和控制. 关于cgroup我们需要了解的它的知识点: 1. 基本概念 cgroup涉及到几个 ...
- :not() 选择器选取除了指定元素以外的所有元素
:not() 选择器选取除了指定元素以外的所有元素; 最近有人那上图问:如果触碰li时背景色和字体都变化,但是已经被选中的(现在是第一行)不变怎么办?:not是一个非常简单方便的办法:加入我给已经被选 ...
- Latex插入项目列表符号
1. 关于 {itemize}里序号的形式 (这个在书里有介绍): latex默认生成的简单列表, 默认为一个小圆点,..... 而我们在写文章时可能想要一些不一样的列表符号, 比如 -, * 之类的 ...
- LNMP架构
LNMP架构介绍 lnmp里的php会启动一个服务,nginx把用户请求的php交给php-fpm处理,比如登录网站php要和mysql做交互,查用户的账号和密码,处理完之后,php-fpm会告诉ng ...
- php实现IP地址和数字相互转换
echo $a=ip2long ("202.97.224.68");//地址转换成数字 系统自带的函数 注:这里面有一个要注意的地方,大概由于PHP无法正确判断转换完的数字类型,出 ...
- mysql-shell的安装和使用
mysql-shell是一个高级的mysql命令行工具.它直接两种模式(交互式&批处理式)三种语言(javascript\python\sql) 1.下载地址 https://dev.mysq ...
- unity调用系统剪切板功能
package com.game.utils; import android.app.Activity; import android.content.ClipData; import android ...
- Struts2动作
ActionContext 每一个请求的处理都在一个独立的线程中.每一个线程都有一个ActionContext对象.它包括了ValueStack和HttpServletRequest的东西. Stru ...
- Python学习之warn()函数
warn()函数位于warnings模块中,用来发出警告,或者忽略它或引发异常. def warn(message, category=None, stacklevel=, source=None) ...
- Itunes connect上传应用视频 app preview时遇到“无法载入文件”的问题
总结一下,上传视频的一个经验吧,在使用safari进行上传的时候,有时出现了问题,上传失败,但是提示语只有一句“无法载入文件,请再次尝试”.这样的提示并不能提供更多的信息,为什么视频无法上传.有这样的 ...