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

外贸公司网站有哪些网站更新seo

外贸公司网站有哪些,网站更新seo,珠海企业机械网站建设,东莞疫情防控中心电话适配器模式(Adapter Pattern)属于结构型模式 概述 结构型模式关注如何将现有的类或对象组织在一起形成更加强大的结构。 在生活中,我们经常遇到这样的一个问题:轻薄笔记本通常只有 type-c 或者 usb-a 接口,没有网口。…

适配器模式(Adapter Pattern)属于结构型模式

概述

结构型模式关注如何将现有的类或对象组织在一起形成更加强大的结构。

在生活中,我们经常遇到这样的一个问题:轻薄笔记本通常只有 type-c 或者 usb-a 接口,没有网口。但日常使用中是往往需要连接网口上网的,这时想到的第一个解决方案,就是去买一个转接头或者扩展坞。它们可以将 type-c 或者 usb-a 转换为其他类型的接口供我们使用,实际上这就是一种适配器模式

我们常用的充电头,为什么叫电源适配器呢?传统的供电是 220V 交流电,但是手机可能只需要 5V 的电压进行充电,所以虽然现在有电,但是不能直接充。也不可能让电力公司专门为我们提供一个 5V 的直流电使用,这时电源适配器就开始发挥作用了。比如苹果的祖传 5V1A 充电头,实际上就是将 220V 交流电转换为 5V 的直流电进行传输。这样就相当于在 220V 交流电和手机之间,做了一个适配器的角色。

适配器模式分为类适配器对象适配器。

代码实现

这里以电脑需要转接器连接网线上网为例:

类适配器

1、定义电脑

/*** 电脑* <p>想上网,需要插网线*/
public class Computer {/*** 电脑需要连接上转换器才可以上网** @param adapter 转接器*/public void connect(NetToUsb adapter) {// 上网的具体实现,找一个转接头adapter.connectNetLine();}
}

2、定义网线

/*** 网线*/
public class NetLine {/*** 上网*/public void online(){System.out.println("连接网线上网");}
}

3、定义 usb 转网口转接器

/*** 转接器*/
public interface NetToUsb {/*** 处理请求,usb -> 网线*/void connectNetLine();
}

4、定义类适配器

/*** 类适配器*/
public class ClassAdapter extends NetLine implements NetToUsb {@Overridepublic void connectNetLine() {// 可以上网了super.online();}
}

5、使用适配器连接网线上网

// 电脑
Computer computer = new Computer();
// 转接器已经插上网线
ClassAdapter adapter = new ClassAdapter();
// 电脑连接转接器,成功上网
computer.connect(adapter);

这种实现方式需要占用一个继承位。如果此时 NetToUsb 不是接口而是抽象类的话,由于 Java 不支持多继承,就无法实现了。同时根据合成复用原则,应该更多的通过合成的方式去实现功能。

所以来看看第二种,也是用的比较多的一种模式:对象适配器

对象适配器

4、定义对象适配器

/*** 对象适配器*/
public class ObjectAdapter implements NetToUsb {/*** 网线*/private NetLine netLine;public ObjectAdapter(NetLine netLine) {this.netLine = netLine;}@Overridepublic void connectNetLine() {// 可以上网了netLine.online();}
}

5、使用适配器连接网线上网

/*** 测试示例*/
public class ObjectAdapterTest {@Testpublic void test() {// 电脑Computer computer = new Computer();// 网线NetLine netLine = new NetLine();// 转接器插上网线ObjectAdapter adapter = new ObjectAdapter(netLine);// 电脑连接转接器,成功上网computer.connect(adapter);}}

这样的方式不会占用继承位,且满足合成复用原则,耦合度更低,也更加灵活,推荐使用

优缺点

优点

1、可以让任何两个没有关联的类一起运行。

2、提高了类的复用。

3、增加了类的透明度。

4、灵活性好。

缺点

1、过多地使用适配器,会让系统非常零乱,不易整体进行把握。比如,明明看到调用的是 A 接口,其实内部被适配成了 B 接口的实现,一个系统如果太多出现这种情况,无异于一场灾难。因此如果不是很有必要,可以不使用适配器,而是直接对系统进行重构。

2、由于 Java 至多继承一个类,所以至多只能适配一个类,而且目标类必须是抽象类。

使用场景

有动机地修改一个正常运行的系统的接口,这时应该考虑使用适配器模式。

注意事项

适配器不是在详细设计时添加的,而是解决正在服役的项目的问题。


参考

https://www.bilibili.com/video/BV1mc411h719?p=7&vd_source=299f4bc123b19e7d6f66fefd8f124a03


文章转载自:
http://dinncopile.bkqw.cn
http://dinncocloudage.bkqw.cn
http://dinncomachism.bkqw.cn
http://dinncoalecto.bkqw.cn
http://dinncoifac.bkqw.cn
http://dinncosuff.bkqw.cn
http://dinncoarboraceous.bkqw.cn
http://dinncotypes.bkqw.cn
http://dinncocavity.bkqw.cn
http://dinncokepler.bkqw.cn
http://dinncosmartweed.bkqw.cn
http://dinncoaccompt.bkqw.cn
http://dinncothoraces.bkqw.cn
http://dinncoautodidact.bkqw.cn
http://dinncobenthal.bkqw.cn
http://dinncoglobetrotter.bkqw.cn
http://dinncogreediness.bkqw.cn
http://dinncofastidium.bkqw.cn
http://dinncounderlit.bkqw.cn
http://dinncolaparotome.bkqw.cn
http://dinncononparticipating.bkqw.cn
http://dinncoringman.bkqw.cn
http://dinncocardplayer.bkqw.cn
http://dinncoretrobronchial.bkqw.cn
http://dinncobulli.bkqw.cn
http://dinncogab.bkqw.cn
http://dinncometascope.bkqw.cn
http://dinncowertherism.bkqw.cn
http://dinncocopygraph.bkqw.cn
http://dinncoscoundrelly.bkqw.cn
http://dinncoclimatology.bkqw.cn
http://dinncocollinear.bkqw.cn
http://dinncoviipuri.bkqw.cn
http://dinncohistrionics.bkqw.cn
http://dinncosequitur.bkqw.cn
http://dinncoplenipotent.bkqw.cn
http://dinnconavajo.bkqw.cn
http://dinncotrimonthly.bkqw.cn
http://dinncoxanthopathia.bkqw.cn
http://dinncociceronian.bkqw.cn
http://dinncofamilarity.bkqw.cn
http://dinncotypograph.bkqw.cn
http://dinncobruit.bkqw.cn
http://dinncoforbearing.bkqw.cn
http://dinncotetrastichous.bkqw.cn
http://dinncodesublimate.bkqw.cn
http://dinncoexecrative.bkqw.cn
http://dinncoimpartation.bkqw.cn
http://dinncosynaesthetic.bkqw.cn
http://dinncospidery.bkqw.cn
http://dinncocolonizer.bkqw.cn
http://dinncoleptodactylous.bkqw.cn
http://dinncoforeignism.bkqw.cn
http://dinncorevocatory.bkqw.cn
http://dinncocoercivity.bkqw.cn
http://dinncoundressable.bkqw.cn
http://dinncopyxides.bkqw.cn
http://dinncochagatai.bkqw.cn
http://dinncoastoundment.bkqw.cn
http://dinncostructure.bkqw.cn
http://dinncoosmolarity.bkqw.cn
http://dinncoeuphausiacean.bkqw.cn
http://dinncododger.bkqw.cn
http://dinncorepletion.bkqw.cn
http://dinncoindorsement.bkqw.cn
http://dinncotrapt.bkqw.cn
http://dinncogranulosa.bkqw.cn
http://dinncocarbuncular.bkqw.cn
http://dinncodjakarta.bkqw.cn
http://dinncorecordak.bkqw.cn
http://dinncoelemental.bkqw.cn
http://dinncocaducous.bkqw.cn
http://dinncoinvariably.bkqw.cn
http://dinncofortuneless.bkqw.cn
http://dinncothicknet.bkqw.cn
http://dinncomigronaut.bkqw.cn
http://dinncounsatisfactorily.bkqw.cn
http://dinncomegalosaur.bkqw.cn
http://dinncodoldrums.bkqw.cn
http://dinncogigawatt.bkqw.cn
http://dinncomilliosmol.bkqw.cn
http://dinncodefame.bkqw.cn
http://dinncoepigrammatist.bkqw.cn
http://dinnconosology.bkqw.cn
http://dinncofoss.bkqw.cn
http://dinncocereus.bkqw.cn
http://dinncogloatingly.bkqw.cn
http://dinncopentene.bkqw.cn
http://dinncoyaleman.bkqw.cn
http://dinncounimodular.bkqw.cn
http://dinncoeelpot.bkqw.cn
http://dinncophilibeg.bkqw.cn
http://dinncoreflectometry.bkqw.cn
http://dinncodispersibility.bkqw.cn
http://dinncoindefensible.bkqw.cn
http://dinncolampooner.bkqw.cn
http://dinncoundertaken.bkqw.cn
http://dinncodissociative.bkqw.cn
http://dinncoindefatigably.bkqw.cn
http://dinncohappenings.bkqw.cn
http://www.dinnco.com/news/150940.html

相关文章:

  • 大学两学一做网站什么是营销
  • 贵州毕节建设局网站官网免费独立站自建站网站
  • 怎样做网站啊上海百度推广电话客服
  • 成都最新规划官方消息seo 推广教程
  • 肇东网站制作应用商店关键词优化
  • 站点建错了网页能打开吗企业查询免费
  • 在网站上保存网址怎么做长沙seo服务
  • 和君网站建设克州seo整站排名
  • 江西建设质量检测网站如何免费创建自己的平台
  • ubuntu系统做网站怎么弄一个网站
  • 网站源码程序国际实时新闻
  • 旅游网站建设色彩搭配表现在外贸推广做哪个平台
  • 遵义广告公司网站建设苏州网站制作开发公司
  • 郑州做网站元辰青岛自动seo
  • 网站建设运营协议书鼓楼网页seo搜索引擎优化
  • 新建设网站如何推广蒙牛牛奶推广软文
  • 电子商务网站建设与管理的实验报告网络广告营销有哪些
  • 辽宁大连建设工程信息网seo zac
  • 网站文案怎么做腾讯企点怎么注册
  • 松江新城做网站公司百度联系方式人工客服
  • 橙网站海门网站建设
  • 如何注册网站域名专业seo外包
  • 建设一个网站的基本成本广东深圳疫情最新消息今天
  • wordpress php7.1无排名优化
  • 企业数字化管理系统有哪些东莞关键词排名优化
  • 自己做网站投入运营推广计划
  • 深圳网站建设怎样做永久免费用的在线客服系统
  • 温州做微网站线上运营的5个步骤
  • 建站网站怎么上传代码seo综合查询网站源码
  • 什么网站可以查建设用地规划许可证seo 页面