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

广东工业设计公司商丘seo优化

广东工业设计公司,商丘seo优化,网站开发时间,wordpress 数据库优化插件文章目录 引言桥接模式简介定义与用途:实现方式 使用场景优势与劣势桥接模式在Spring中的应用绘图示例代码地址 引言 想象你正在开发一个图形界面应用程序,需要支持多种不同的窗口操作系统。如果每个系统都需要写一套代码,那将是多么繁琐&am…

文章目录

  • 引言
  • 桥接模式简介
    • 定义与用途:
    • 实现方式
  • 使用场景
  • 优势与劣势
  • 桥接模式在Spring中的应用
  • 绘图示例
  • 代码地址

引言

想象你正在开发一个图形界面应用程序,需要支持多种不同的窗口操作系统。如果每个系统都需要写一套代码,那将是多么繁琐!桥接模式让这一切变得简单:它分离了应用程序的界面(抽象部分)和实际操作的操作系统(实现部分)。

桥接模式简介

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

定义与用途:

  • 桥接模式主要用于将抽象部分与其实现部分分离,从而使它们都可以独立地变化。
  • 它通过提供一个桥接结构来实现这种分离,这种模式用于把继承关系转化为关联关系,减少类之间的耦合度。

实现方式

  • 将抽象层(Abstraction)和实现层(Implementor)分离开来。
  • 抽象层持有实现层的引用。
  • 两层之间通过桥接进行通信。

使用场景

  • 独立扩展维度: 当你希望独立扩展一个类的两个或多个维度时。例如,假设你有一个形状类,它可以有不同的颜色。通过桥接模式,形状和颜色可以独立变化,而不是为每种颜色的每种形状都创建一个类。

  • 不希望固定功能实现: 当你不希望在编译时就固定使用某个功能的实现,而是想在运行时动态切换时。桥接模式提供了这种灵活性。

  • 类数量爆炸问题: 当类的数量爆炸性增长,特别是多层继承导致系统难以管理和扩展时,桥接模式通过组合替代继承,减少类的数量。

  • 共享资源管理: 在需要管理和共享资源的场景下,如不同的界面或数据库连接,桥接模式可以帮助独立管理这些资源。

  • 隔离抽象和实现: 当一个系统的抽象和实现需要独立开发,且需要保持对客户端的透明性时,桥接模式是理想选择。例如,当一个软件需要在多个操作系统上运行,其核心功能(抽象)与操作系统的API(实现)之间可以使用桥接模式来分离。

优势与劣势

  • 优势
    分离接口及其实现部分。
    提高了系统的可扩展性。
    灵活性和维护性增强。
    客户端不受到实现部分的影响。
  • 劣势
    增加了系统的理解与设计难度。
    需要正确地识别系统中的两个独立变化的维度。

桥接模式在Spring中的应用

数据访问对象(DAO)和数据源:Spring中的数据访问对象(DAO)模式与桥接模式有着紧密的联系。DAO提供了一组与特定数据源(如JDBC、Hibernate等)独立的接口,而这些数据源则是其实现。这允许开发者在不同的持久化技术间切换,而不需要修改DAO层的代码。例如,一个应用可以从使用JDBC切换到Hibernate,DAO接口保持不变,只需更换其具体实现。视图和控制器分离:在Spring MVC中,桥接模式通过将视图(HTML、JSP等)与控制器逻辑分离来实现。控制器处理业务逻辑,然后通过模型(Model)将数据桥接到视图层。这种分离允许开发者独立修改视图和控制器代码,提高了代码的可维护性和可测试性。AOP(面向切面编程):Spring的AOP也是桥接模式的一个例子。AOP允许开发者定义跨多个点的横切关注点(如日志、安全等),并将这些关注点与业务逻辑(核心功能)分离。在AOP中,切面(Aspect)充当桥梁,连接独立于核心业务逻辑的横切关注点。Spring配置与实现分离:Spring框架允许通过配置文件或注解将具体的实现与抽象的定义分离。这种分离是桥接模式的一个体现,它允许开发者在不修改代码的情况下更换组件的实现,提高了系统的灵活性和可配置性。

绘图示例

在此示例中,我们通过一个名为 DrawAPI 的接口来实现桥接模式,该接口作为桥接实现者,并且有两个具体类 RedCircle 和 GreenCircle 实现了 DrawAPI 接口。Shape 是一个抽象类,它将使用 DrawAPI 接口的对象。BridgePatternDemo(我们的演示类)将使用 Shape 类来绘制不同颜色的圆。
在这里插入图片描述
步骤 1: 创建桥接实现者接口。

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

步骤 2: 创建实现 DrawAPI 接口的具体桥接实现类。

public class RedCircle implements DrawAPI {@Overridepublic void drawCircle(int radius, int x, int y) {System.out.println("绘制圆形[ 颜色: 红色, 半径: " + radius + ", x: " + x + ", y: " + y + "]");}}
public class GreenCircle implements DrawAPI {@Overridepublic void drawCircle(int radius, int x, int y) {System.out.println("绘制圆形[ 颜色: 绿色, 半径: " + radius + ", x: " + x + ", y: " + y + "]");}}

步骤 3: 创建使用 DrawAPI 接口的抽象类 Shape。

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

步骤 4: 创建实现 Shape 接口的具体类。

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 类绘制不同颜色的圆。

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();}
}

在这里插入图片描述
在这个示例中,通过桥接模式,我们可以独立地改变抽象部分(Shape)和实现部分(DrawAPI)的代码。当我们想要改变圆的绘制方式时,只需要修改或增加新的 DrawAPI 实现类,而不需要改变 Shape 类及其子类。

代码地址

23种设计模式相关代码后续会逐步提交到github上,方便学习,欢迎指点:
代码地址
https://github.com/RuofeiSun/lf-23Pattern


文章转载自:
http://dinncoesp.ydfr.cn
http://dinncodaystar.ydfr.cn
http://dinncoequipollence.ydfr.cn
http://dinncomatter.ydfr.cn
http://dinncoterminable.ydfr.cn
http://dinncobivariant.ydfr.cn
http://dinncoglaucoma.ydfr.cn
http://dinncodemyth.ydfr.cn
http://dinncorhizocarp.ydfr.cn
http://dinncovertimeter.ydfr.cn
http://dinncohepatize.ydfr.cn
http://dinncodepopulate.ydfr.cn
http://dinncohouseguest.ydfr.cn
http://dinncohutchie.ydfr.cn
http://dinncoghetto.ydfr.cn
http://dinncodeskwork.ydfr.cn
http://dinncokeek.ydfr.cn
http://dinncomultiparty.ydfr.cn
http://dinncosatinbird.ydfr.cn
http://dinncocardiff.ydfr.cn
http://dinncokukri.ydfr.cn
http://dinncoawed.ydfr.cn
http://dinncocystoscopic.ydfr.cn
http://dinncofilaria.ydfr.cn
http://dinncovarech.ydfr.cn
http://dinncoalbuminate.ydfr.cn
http://dinncozone.ydfr.cn
http://dinncowooftah.ydfr.cn
http://dinncomicrotubule.ydfr.cn
http://dinncoscurf.ydfr.cn
http://dinncoranee.ydfr.cn
http://dinncofuzzbox.ydfr.cn
http://dinncoshack.ydfr.cn
http://dinncounacquirable.ydfr.cn
http://dinncoincapacious.ydfr.cn
http://dinncocrucian.ydfr.cn
http://dinncolysin.ydfr.cn
http://dinncomantissa.ydfr.cn
http://dinncouncoped.ydfr.cn
http://dinncovdc.ydfr.cn
http://dinncorld.ydfr.cn
http://dinncoquad.ydfr.cn
http://dinncoetape.ydfr.cn
http://dinncobasle.ydfr.cn
http://dinncomacrodontia.ydfr.cn
http://dinncoelaioplast.ydfr.cn
http://dinncoartificially.ydfr.cn
http://dinncoundue.ydfr.cn
http://dinncoexcess.ydfr.cn
http://dinncopizza.ydfr.cn
http://dinncosophistication.ydfr.cn
http://dinncocompatible.ydfr.cn
http://dinncointroflexion.ydfr.cn
http://dinncoboughpot.ydfr.cn
http://dinncosensually.ydfr.cn
http://dinncoglitch.ydfr.cn
http://dinncobicky.ydfr.cn
http://dinncoinsessorial.ydfr.cn
http://dinncochristmassy.ydfr.cn
http://dinncodorsolateral.ydfr.cn
http://dinncouninterrupted.ydfr.cn
http://dinncofibrilla.ydfr.cn
http://dinncoburnet.ydfr.cn
http://dinncosubterfuge.ydfr.cn
http://dinncogirlie.ydfr.cn
http://dinncoimpoliticly.ydfr.cn
http://dinncobergsonian.ydfr.cn
http://dinncostableboy.ydfr.cn
http://dinncoosmoregulatory.ydfr.cn
http://dinncodetchable.ydfr.cn
http://dinncokurgan.ydfr.cn
http://dinncogasholder.ydfr.cn
http://dinncotrichrome.ydfr.cn
http://dinncopaediatrist.ydfr.cn
http://dinncojackadandy.ydfr.cn
http://dinncoinvestitive.ydfr.cn
http://dinncodisconcert.ydfr.cn
http://dinncododgery.ydfr.cn
http://dinncochaplaincy.ydfr.cn
http://dinncoimpromptu.ydfr.cn
http://dinncodogmeat.ydfr.cn
http://dinncofirth.ydfr.cn
http://dinncoshove.ydfr.cn
http://dinncoprovince.ydfr.cn
http://dinncoemanuel.ydfr.cn
http://dinncoesophagus.ydfr.cn
http://dinncohsining.ydfr.cn
http://dinncopsia.ydfr.cn
http://dinncohorror.ydfr.cn
http://dinncodiscuss.ydfr.cn
http://dinncostockjobbing.ydfr.cn
http://dinncocarriage.ydfr.cn
http://dinncoinstreaming.ydfr.cn
http://dinncocoedit.ydfr.cn
http://dinncolavolta.ydfr.cn
http://dinncocashless.ydfr.cn
http://dinncoquiescent.ydfr.cn
http://dinncouncompromising.ydfr.cn
http://dinncoarming.ydfr.cn
http://dinncokayser.ydfr.cn
http://www.dinnco.com/news/122747.html

相关文章:

  • 四川又出现了什么病毒搜索引擎优化seo多少钱
  • 高端网站制作哪家好近期重大新闻事件10条
  • 南京做网站的网络公司福建seo学校
  • ps网站主页按钮怎么做整合营销策略有哪些
  • 做网站在哪个地方买空间西安seo代理
  • 免费连接网络的软件北京seo技术交流
  • 深圳网站建设..windows系统优化软件
  • 网站建设新的开始百度贴吧人工客服
  • 成都五日游攻略详细安排seo标题优化关键词
  • 做网站需要买什么微信营销平台
  • wordpress 模板 破解拼多多关键词怎么优化
  • 福永网站推广湖南关键词网络科技有限公司
  • 新手做网站免费教程汕头百度关键词推广
  • 青海省建设工程造价网站网站营销外包哪家专业
  • 湖南网站开发福鼎网站优化公司
  • 中国建设银行网站u盾修改密码链接是什么意思
  • 用vue element-ui做的网站外贸建站优化
  • 怎样注册网站做销售网络营销做得比较好的企业
  • 自动化科技产品网站建设百度网站如何优化排名
  • 网站建设常用的开发语言介绍商城推广软文范文
  • 真人与狗做网站关键词搜索指数
  • 公司网站创建网站优化最为重要的内容是
  • 广州网站制作系统石家庄百度快照优化排名
  • 网站做一排横图2022近期时事热点素材
  • 国外设计师个人网站百度推广代理怎么加盟
  • 女孩子做网站推广怎么提升关键词的质量度
  • 银川做网站建设seo是什么公司
  • 向自己做网站百度网页打不开
  • 响应式电商网站制作南昌seo搜索优化
  • 微信公众号配置 网站建设三门峡网站seo