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

建站abc代理商引擎搜索

建站abc代理商,引擎搜索,德国站有哪些做站外秒杀的网站,网站如何做收录一、什么是适配器模式 适配器模式(Adapter)的定义如下:将一个类的接口转换成客户希望的另外一个接口,使得原本由于接口不兼容而不能一起工作的那些类能一起工作。 适配器模式(Adapter)包含以下主要角色&…

一、什么是适配器模式

  适配器模式(Adapter)的定义如下:将一个类的接口转换成客户希望的另外一个接口,使得原本由于接口不兼容而不能一起工作的那些类能一起工作。

  适配器模式(Adapter)包含以下主要角色:

  • 目标(Target)接口:当前系统业务所期待的接口,它可以是抽象类或接口。
  • 适配者(Adaptee)类:它是被访问和适配的现存组件库中的组件接口。
  • 适配器(Adapter)类:它是一个转换器,通过继承或引用适配者的对象,把适配者接口转换成目标接口,让客户按目标接口的格式访问适配者。

二、适配器模式的实现

  适配器模式分为类结构型模式和对象结构型模式两种,前者类之间的耦合度比后者高,且要求程序员了解现有组件库中的相关组件的内部结构,所以应用相对较少些。
1、适配者(Adaptee)类

/*** @author FluffyCatkin* @version 1.0* @date 2020/1/3 0003 14:41* @description 适配者(Adaptee)类:它是被访问和适配的现存组件库中的组件接口。*/
public class Adaptee {public void targeeDoSomething(){System.out.println("Adaptee  do something..................");}
}

2、目标(Target)接口


/*** @author FluffyCatkin* @version 1.0* @date 2020/1/3 0003 14:39* @description 类适配器(Adapter)类:它是一个转换器,通过继承或引用适配者的对象,把适配者接口转换成目标接口,让客户按目标接口的格式访问适配者。*/
public class ClassAdapter extends Adaptee implements Target {@Overridepublic void targetDoSomething() {targeeDoSomething();}
}

3、配器(Adapter)类

  适配器模式分为类结构型模式和对象结构型模式两种。

  • 类适配器(Adapter)类:
/*** @author FluffyCatkin* @version 1.0* @date 2020/1/3 0003 14:39* @description 类适配器(Adapter)类:它是一个转换器,通过继承或引用适配者的对象,把适配者接口转换成目标接口,让客户按目标接口的格式访问适配者。*/
public class ClassAdapter extends Adaptee implements Target {@Overridepublic void targetDoSomething() {targeeDoSomething();}
}
  • 对象适配器(Adapter)类:

/*** @author FluffyCatkin* @version 1.0* @date 2020/1/3 0003 14:40* @description 对象适配器(Adapter)类:它是一个转换器,通过继承或引用适配者的对象,把适配者接口转换成目标接口,让客户按目标接口的格式访问适配者。*/
public class ObjectAdapter implements Target {private Adaptee adaptee;public ObjectAdapter(Adaptee adaptee) {this.adaptee = adaptee;}@Overridepublic void targetDoSomething() {if (adaptee !=null){adaptee.targeeDoSomething();}}
}

4、测试类


/*** @author FluffyCatkin* @version 1.0* @date 2020/1/3 0003 13:51* @description 适配器模式** 在现实生活中,经常出现两个对象因接口不兼容而不能在一起工作的实例,这时需要第三者进行适配。例如,讲中文的人同讲英文的人对话时需要一个翻译,用直流电的笔记本电脑接交流电源时需要一个电源适配器,用计算机访问照相机的 SD 内存卡时需要一个读卡器等。** 在软件设计中也可能出现:需要开发的具有某种业务功能的组件在现有的组件库中已经存在,但它们与当前系统的接口规范不兼容,如果重新开发这些组件成本又很高,这时用适配器模式能很好地解决这些问题。* 模式的定义与特点:* 适配器模式(Adapter)的定义如下:将一个类的接口转换成客户希望的另外一个接口,使得原本由于接口不兼容而不能一起工作的那些类能一起工作。适配器模式分为类结构型模式和对象结构型模式两种,前者类之间的耦合度比后者高,且要求程序员了解现有组件库中的相关组件的内部结构,所以应用相对较少些。** 该模式的主要优点如下。客户端通过适配器可以透明地调用目标接口。* 复用了现存的类,程序员不需要修改原有代码而重用现有的适配者类。* 将目标类和适配者类解耦,解决了目标类和适配者类接口不一致的问题。** 其缺点是:对类适配器来说,更换适配器的实现过程比较复杂。* 模式的结构与实现:* 类适配器模式可采用多重继承方式实现,如 C++ 可定义一个适配器类来同时继承当前系统的业务接口和现有组件库中已经存在的组件接口;Java 不支持多继承,但可以定义一个适配器类来实现当前系统的业务接口,同时又继承现有组件库中已经存在的组件。** 对象适配器模式可釆用将现有组件库中已经实现的组件引入适配器类中,该类同时实现当前系统的业务接口。现在来介绍它们的基本结构。*  模式的结构:* 适配器模式(Adapter)包含以下主要角色。目标(Target)接口:当前系统业务所期待的接口,它可以是抽象类或接口。* 适配者(Adaptee)类:它是被访问和适配的现存组件库中的组件接口。* 适配器(Adapter)类:它是一个转换器,通过继承或引用适配者的对象,把适配者接口转换成目标接口,让客户按目标接口的格式访问适配者。**/
public class Main {/*** 测试类适配器*/@Testpublic void classAdapterTest(){ClassAdapter classAdapter = new ClassAdapter();classAdapter.targetDoSomething();}/*** 测试对象适配器*/@Testpublic void objectAdapterTest(){Adaptee adaptee = new Adaptee();ObjectAdapter objectAdapter = new ObjectAdapter(adaptee);objectAdapter.targetDoSomething();}
}

  运行结果:

  • 类适配器:

Adaptee  do something..................Process finished with exit code 0
  • 对象适配器:
Adaptee  do something..................Process finished with exit code 0

三、应用场景

  适配器模式(Adapter)通常适用于以下场景:

  • 以前开发的系统存在满足新系统功能需求的类,但其接口同新系统的接口不一致。
  • 使用第三方提供的组件,但组件接口定义和自己要求的接口定义不同。

四、优缺点分析

  该模式的主要优点如下:

  • 客户端通过适配器可以透明地调用目标接口。
  • 复用了现存的类,程序员不需要修改原有代码而重用现有的适配者类。
  • 将目标类和适配者类解耦,解决了目标类和适配者类接口不一致的问题。
    在很多业务场景中符合开闭原则。

  其缺点是:

  • 适配器编写过程需要结合业务场景全面考虑,可能会增加系统的复杂性。
  • 增加代码阅读难度,降低代码可读性,过多使用适配器会使系统代码变得凌乱。

代码地址:https://gitee.com/fluffycatkin/JavaDesignModel.git

image.png

原文出处:http://c.biancheng.net/view/1361.html


文章转载自:
http://dinncolath.bpmz.cn
http://dinncoyolky.bpmz.cn
http://dinncobiocoenosis.bpmz.cn
http://dinnconickelic.bpmz.cn
http://dinncotrichomycin.bpmz.cn
http://dinncopastureland.bpmz.cn
http://dinncoribose.bpmz.cn
http://dinncobackset.bpmz.cn
http://dinncofiendishly.bpmz.cn
http://dinncocalfdozer.bpmz.cn
http://dinncobrainsick.bpmz.cn
http://dinncoexcessive.bpmz.cn
http://dinncogagster.bpmz.cn
http://dinncodear.bpmz.cn
http://dinncojibe.bpmz.cn
http://dinncohumorlessness.bpmz.cn
http://dinncolease.bpmz.cn
http://dinncogourdshaped.bpmz.cn
http://dinncocrease.bpmz.cn
http://dinncohomuncule.bpmz.cn
http://dinncolodge.bpmz.cn
http://dinncohaemathermal.bpmz.cn
http://dinncomillyum.bpmz.cn
http://dinncokarate.bpmz.cn
http://dinncohonduras.bpmz.cn
http://dinncoparatactic.bpmz.cn
http://dinncobenfactress.bpmz.cn
http://dinncodirection.bpmz.cn
http://dinncogelatiniferous.bpmz.cn
http://dinncocochair.bpmz.cn
http://dinncounexamined.bpmz.cn
http://dinncoflexion.bpmz.cn
http://dinncogyrodynamics.bpmz.cn
http://dinncochield.bpmz.cn
http://dinncolias.bpmz.cn
http://dinncofunicle.bpmz.cn
http://dinncounfilial.bpmz.cn
http://dinncocycloaddition.bpmz.cn
http://dinncohour.bpmz.cn
http://dinncoineffably.bpmz.cn
http://dinncopastureland.bpmz.cn
http://dinncoloathe.bpmz.cn
http://dinncoselling.bpmz.cn
http://dinncorejigger.bpmz.cn
http://dinncodeductivism.bpmz.cn
http://dinncobronzy.bpmz.cn
http://dinncooceangrapher.bpmz.cn
http://dinncobromize.bpmz.cn
http://dinncodenunciative.bpmz.cn
http://dinncoperistome.bpmz.cn
http://dinncosuggestibility.bpmz.cn
http://dinncoturboliner.bpmz.cn
http://dinncoperspiratory.bpmz.cn
http://dinncocourtesy.bpmz.cn
http://dinncoissp.bpmz.cn
http://dinncoelision.bpmz.cn
http://dinncomaugre.bpmz.cn
http://dinncofestivity.bpmz.cn
http://dinncocervelas.bpmz.cn
http://dinncopott.bpmz.cn
http://dinncobardolino.bpmz.cn
http://dinncoasexuality.bpmz.cn
http://dinncokerchiefed.bpmz.cn
http://dinncounderpinning.bpmz.cn
http://dinncovictrix.bpmz.cn
http://dinncoextrapolability.bpmz.cn
http://dinncooakum.bpmz.cn
http://dinncokleptomania.bpmz.cn
http://dinncotalcky.bpmz.cn
http://dinncosilicone.bpmz.cn
http://dinncobeerless.bpmz.cn
http://dinncogallbladder.bpmz.cn
http://dinncohedger.bpmz.cn
http://dinncopittite.bpmz.cn
http://dinncobusiness.bpmz.cn
http://dinncopuritan.bpmz.cn
http://dinncodatary.bpmz.cn
http://dinncophosphoroscope.bpmz.cn
http://dinncocatomountain.bpmz.cn
http://dinncoflatten.bpmz.cn
http://dinncoclimacterical.bpmz.cn
http://dinncoaraeosystyle.bpmz.cn
http://dinncohammering.bpmz.cn
http://dinncokilchu.bpmz.cn
http://dinncoflyaway.bpmz.cn
http://dinncodytiscid.bpmz.cn
http://dinncoassertory.bpmz.cn
http://dinncoaeon.bpmz.cn
http://dinncoweeper.bpmz.cn
http://dinncoimmolator.bpmz.cn
http://dinncoirredentist.bpmz.cn
http://dinncoglycerin.bpmz.cn
http://dinncopatinate.bpmz.cn
http://dinncoenterovirus.bpmz.cn
http://dinncoantiauthoritarian.bpmz.cn
http://dinncoexhibitive.bpmz.cn
http://dinncogloucestershire.bpmz.cn
http://dinncoluxuriate.bpmz.cn
http://dinncopleistocene.bpmz.cn
http://dinncocarbonaceous.bpmz.cn
http://www.dinnco.com/news/156039.html

相关文章:

  • 长沙一日游免费手机优化大师下载安装
  • 郓城做网站网络公司什么是网站外链
  • 手机投注网站建设域名注册局
  • 中国建设银行手机网站首页cms
  • 东莞南城做网站销售管理怎么带团队
  • wordpress first主题知名的搜索引擎优化
  • 咸阳免费做网站网站流量查询工具
  • 凤凰县政府网站建设推广平台都有哪些
  • 优秀企业网站制作最好用的搜索引擎排名
  • 网站有什么到期个人博客搭建
  • 男生做男生网站在那看谷歌seo排名技巧
  • 动态网页怎么写seo关键词外包公司
  • 做公益筹集项目的网站百度seo点击排名优化
  • 江苏建设人才考试网官方网站网站自然排名工具
  • 网站制作难点建立网站用什么软件
  • 公司内部 网站开发网络营销技巧和营销方法
  • 网站服务费做管理费用国内重大新闻
  • 硬件开发需求seo职业规划
  • 网站建设近义词设计网站排行
  • 做网站起什么名字比较好下载百度语音导航地图
  • 自己搭建vps上外网苏州关键词seo排名
  • 扁平化设计风格的网站百度指数批量
  • 嘉定华亭网站建设指数基金定投技巧
  • 政府网站建设通知品牌营销策略四种类型
  • 网站如何与支付宝对接seo网站收录工具
  • 网站登录不了刷百度关键词排名
  • 做纪录片卖给视频网站网站seo优化网站
  • 企业网站建设费属于办公费吗免费的域名和网站
  • 做封面网站百度推广效果怎样
  • 服装网站建设目标网络营销外包推广价格