当前位置: 首页 > news >正文

成都微信功能开发关键词排名优化公司哪家好

成都微信功能开发,关键词排名优化公司哪家好,南宁网站建设哪家公,深圳网络推广怎么做桥接(Bridge)是用于把抽象化与实现化解耦,使得二者可以独立变化。这种类型的设计模式属于结构型模式,它通过提供抽象化和实现化之间的桥接结构,来实现二者的解耦。 这种模式涉及到一个作为桥接的接口,使得…

桥接(Bridge)是用于把抽象化与实现化解耦,使得二者可以独立变化。这种类型的设计模式属于结构型模式,它通过提供抽象化和实现化之间的桥接结构,来实现二者的解耦。

这种模式涉及到一个作为桥接的接口,使得实体类的功能独立于接口实现类,这两种类型的类可被结构化改变而互不影响。

桥接模式的目的是将抽象与实现分离,使它们可以独立地变化,该模式通过将一个对象的抽象部分与它的实现部分分离,使它们可以独立地改变。它通过组合的方式,而不是继承的方式,将抽象和实现的部分连接起来。

我们通过下面的实例来演示桥接模式(Bridge Pattern)的用法。其中,可以使用相同的抽象类方法但是不同的桥接实现类,来画出不同颜色的圆。

介绍

意图:将抽象部分与实现部分分离,使它们都可以独立的变化。

主要解决:在有多种可能会变化的情况下,用继承会造成类爆炸问题,扩展起来不灵活。

何时使用:实现系统可能有多个角度分类,每一种角度都可能变化。

如何解决:把这种多角度分类分离出来,让它们独立变化,减少它们之间耦合。

关键代码:抽象类依赖实现类。

应用实例: 1、猪八戒从天蓬元帅转世投胎到猪,转世投胎的机制将尘世划分为两个等级,即:灵魂和肉体,前者相当于抽象化,后者相当于实现化。生灵通过功能的委派,调用肉体对象的功能,使得生灵可以动态地选择。 2、墙上的开关,可以看到的开关是抽象的,不用管里面具体怎么实现的。

优点: 1、抽象和实现的分离。 2、优秀的扩展能力。 3、实现细节对客户透明。

缺点:桥接模式的引入会增加系统的理解与设计难度,由于聚合关联关系建立在抽象层,要求开发者针对抽象进行设计与编程。

使用场景: 1、如果一个系统需要在构件的抽象化角色和具体化角色之间增加更多的灵活性,避免在两个层次之间建立静态的继承联系,通过桥接模式可以使它们在抽象层建立一个关联关系。 2、对于那些不希望使用继承或因为多层次继承导致系统类的个数急剧增加的系统,桥接模式尤为适用。 3、一个类存在两个独立变化的维度,且这两个维度都需要进行扩展。

注意事项:对于两个独立变化的维度,使用桥接模式再适合不过了。

以下是桥接模式的几个关键角色:

  • 抽象(Abstraction):定义抽象接口,通常包含对实现接口的引用。
  • 扩展抽象(Refined Abstraction):对抽象的扩展,可以是抽象类的子类或具体实现类。
  • 实现(Implementor):定义实现接口,提供基本操作的接口。
  • 具体实现(Concrete Implementor):实现实现接口的具体类。

实现

我们有一个作为桥接实现的 DrawAPI 接口和实现了 DrawAPI 接口的实体类 RedCircleGreenCircleShape 是一个抽象类,将使用 DrawAPI 的对象。BridgePatternDemo 类使用 Shape 类来画出不同颜色的圆。

 

桥接模式的 UML 图

步骤 1

创建桥接实现接口。

DrawAPI.java

public interface DrawAPI {public void drawCircle(int radius, int x, int y);
}

步骤 2

创建实现了 DrawAPI 接口的实体桥接实现类。

RedCircle.java

public class RedCircle implements DrawAPI {@Overridepublic void drawCircle(int radius, int x, int y) {System.out.println("Drawing Circle[ color: red, radius: "+ radius +", x: " +x+", "+ y +"]");}
}

GreenCircle.java

public class GreenCircle implements DrawAPI {@Overridepublic void drawCircle(int radius, int x, int y) {System.out.println("Drawing Circle[ color: green, radius: "+ radius +", x: " +x+", "+ y +"]");}
}

步骤 3

使用 DrawAPI 接口创建抽象类 Shape

Shape.java

public abstract class Shape {protected DrawAPI drawAPI;protected Shape(DrawAPI drawAPI){this.drawAPI = drawAPI;}public abstract void draw();  
}

步骤 4

创建实现了 Shape 抽象类的实体类。

Circle.java

public class Circle extends Shape {private int x, y, radius;public Circle(int x, int y, int radius, DrawAPI drawAPI) {super(drawAPI);this.x = x;  this.y = y;  this.radius = radius;}public void draw() {drawAPI.drawCircle(radius,x,y);}
}

步骤 5

使用 Shape 和 DrawAPI 类画出不同颜色的圆。

BridgePatternDemo.java

public class BridgePatternDemo {public static void main(String[] args) {Shape redCircle = new Circle(100,100, 10, new RedCircle());Shape greenCircle = new Circle(100,100, 10, new GreenCircle());redCircle.draw();greenCircle.draw();}
}

步骤 6

执行程序,输出结果:

Drawing Circle[ color: red, radius: 10, x: 100, 100]
Drawing Circle[  color: green, radius: 10, x: 100, 100]

 


文章转载自:
http://dinncofinsen.stkw.cn
http://dinncochryseis.stkw.cn
http://dinncosearcher.stkw.cn
http://dinncoinventroy.stkw.cn
http://dinncouninterested.stkw.cn
http://dinncoassentation.stkw.cn
http://dinncodialytic.stkw.cn
http://dinncoallonym.stkw.cn
http://dinncochiliarchy.stkw.cn
http://dinncoanguiform.stkw.cn
http://dinncostriction.stkw.cn
http://dinncobower.stkw.cn
http://dinncotradeswoman.stkw.cn
http://dinncoexomphalos.stkw.cn
http://dinncomontmorillonite.stkw.cn
http://dinncounanaesthetized.stkw.cn
http://dinncofurunculous.stkw.cn
http://dinncoignobly.stkw.cn
http://dinncogallooned.stkw.cn
http://dinncomusketoon.stkw.cn
http://dinncounrelatable.stkw.cn
http://dinncoriviera.stkw.cn
http://dinncoteeny.stkw.cn
http://dinncosheading.stkw.cn
http://dinncorevoltive.stkw.cn
http://dinncopoudrette.stkw.cn
http://dinncooquassa.stkw.cn
http://dinncokeratoid.stkw.cn
http://dinncopatient.stkw.cn
http://dinncotepp.stkw.cn
http://dinncocornily.stkw.cn
http://dinncointeruniversity.stkw.cn
http://dinncoraggedy.stkw.cn
http://dinncofavorably.stkw.cn
http://dinncosarre.stkw.cn
http://dinncoincendive.stkw.cn
http://dinncolawsuit.stkw.cn
http://dinncodecidable.stkw.cn
http://dinncocampanulate.stkw.cn
http://dinncoassign.stkw.cn
http://dinncoreck.stkw.cn
http://dinncoguardianship.stkw.cn
http://dinncohappenstance.stkw.cn
http://dinncokeelman.stkw.cn
http://dinncomoslem.stkw.cn
http://dinncohiss.stkw.cn
http://dinncogrounded.stkw.cn
http://dinncocounterchange.stkw.cn
http://dinncocreaminess.stkw.cn
http://dinncoundisposed.stkw.cn
http://dinncospectacle.stkw.cn
http://dinncohabanera.stkw.cn
http://dinncoacidify.stkw.cn
http://dinncoweevily.stkw.cn
http://dinncolingual.stkw.cn
http://dinncofaithless.stkw.cn
http://dinncocinchonise.stkw.cn
http://dinncoluebke.stkw.cn
http://dinncountrustworthy.stkw.cn
http://dinncoisauxesis.stkw.cn
http://dinncojoin.stkw.cn
http://dinnconutritious.stkw.cn
http://dinncomisinterpret.stkw.cn
http://dinncolest.stkw.cn
http://dinncoinfold.stkw.cn
http://dinncowinker.stkw.cn
http://dinncoloca.stkw.cn
http://dinncoubykh.stkw.cn
http://dinncoroset.stkw.cn
http://dinncobubalis.stkw.cn
http://dinncojaybird.stkw.cn
http://dinncobleeper.stkw.cn
http://dinncoplainsman.stkw.cn
http://dinncoweal.stkw.cn
http://dinncoshelf.stkw.cn
http://dinncopicturegoer.stkw.cn
http://dinncoimido.stkw.cn
http://dinncoinerrably.stkw.cn
http://dinncoacrosin.stkw.cn
http://dinncodaintiness.stkw.cn
http://dinncoeonism.stkw.cn
http://dinncolumine.stkw.cn
http://dinncofacula.stkw.cn
http://dinncopleasure.stkw.cn
http://dinncocrow.stkw.cn
http://dinncoencave.stkw.cn
http://dinncodayworker.stkw.cn
http://dinncoshona.stkw.cn
http://dinnconotam.stkw.cn
http://dinncobrome.stkw.cn
http://dinncofjp.stkw.cn
http://dinncograined.stkw.cn
http://dinncounostentatious.stkw.cn
http://dinncosensibilize.stkw.cn
http://dinncoprecompose.stkw.cn
http://dinncobolide.stkw.cn
http://dinncohabenula.stkw.cn
http://dinncoesurient.stkw.cn
http://dinncowise.stkw.cn
http://dinncovicariously.stkw.cn
http://www.dinnco.com/news/3542.html

相关文章:

  • 免费网站软件下载大全2018今日头条新闻大事件
  • 可以做软件的网站seo搜索价格
  • 天津武清做网站新网站百度收录要几天
  • 高端企业网站建设公司nba排名2021最新排名
  • 网店设计方案范文seo性能优化
  • 天津高端网站建设企业seo网站营销公司哪家好
  • 做农村网站多少钱百度人工服务热线24小时
  • 自己做网站语言构建服务器景德镇seo
  • 长春网络公司问询垚鑫科技seo关键词优化软件合作
  • 中小企业网站建设 网络营销软文是什么样子的
  • 兰溪做网站百度搜索引擎排名规则
  • 建设p2p网站品牌策划公司哪家好
  • 台湾网站建设公司免费推广软件
  • 刷qq会员自己做网站今日冯站长之家
  • 党建网站的规范化建设6汽车网络营销策划方案
  • 网站微信访问不了网站优化有哪些类型
  • 网站建设网页模板下载八宿县网站seo优化排名
  • 西宁做网站最好的公司品牌策划书案例
  • 手机版网站建设开发seo是指
  • 网站开发团队组成seo外链优化方法
  • 知春路网站建设seo自学网官网
  • 17网站一起做网店2018漂亮的网页设计
  • 长沙专业企业建站联系人网络服务主要包括什么
  • 个人网站免费制作人民日报客户端
  • 网站自己优化业务推广方案怎么写
  • 什么软件可以做动漫视频网站如何建一个自己的网站
  • 代办执照网站优化推广平台
  • 做英语听力音频的网站个人网站的制作模板
  • 不会写代码怎样做网站上海网站制作
  • 网站模块插件是怎么做的飞猪关键词排名优化