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

微信生活门户网站源码旅游网站建设案例分析

微信生活门户网站源码,旅游网站建设案例分析,兴化网页定制,wordpress 正在执行例行维护适配器模式 适配器模式是一种结构型设计模式。作用#xff1a;当接口无法和类匹配到一起工作时#xff0c;通过适配器将接口变换成可以和类匹配到一起的接口。#xff08;注#xff1a;适配器模式主要解决接口兼容性问题#xff09; 适配器的优点与缺点#xff1a; 优…适配器模式 适配器模式是一种结构型设计模式。作用当接口无法和类匹配到一起工作时通过适配器将接口变换成可以和类匹配到一起的接口。注适配器模式主要解决接口兼容性问题 适配器的优点与缺点 优点复用性更强对于那些和目标接口差别不是很大的类通过适配器可以让这些类达到很好的复用减少代码的书写。并且在适配中可以添加一些方法来扩展系统的功能扩展性更好 缺点用多了会让系统看起来杂乱无章。比如明明调用的是接口A结构里面的内容以及被修改成了接口B。一般建议直接对系统进行重构。 适配器模式结构 源(Adaptee)需要被适配的对象或类型。 适配器(Adapter)连接目标和源的中间对象负责将Adaptee转换为Target。 目标(Target)目标角色即被转换后的接口。 适配器模式实现方式由三种类适配器模式、对象适配器模式、接口适配器模式。 三种模式的特点 类适配器模式类适配器使用的是继承的方式一般来说无法对其子类进行适配 对象适配器模式对象适配器使用的是组合的方式子孙类都可以被适配。另外对象适配器对于增加一些新行为非常方便而且新增加的行为同时适用于所有的源。 接口适配器模式又称缺省适配器模式接口适配器模式缺省适配模式基本思想是为一个接口提供缺省实现这样子类可以从这个缺省实现进行扩展而不必从原有接口进行扩展。 一、类适配器模式 类适配器即是适配一个类 下发远控命令使用空调远控命令适配器适配公共远控命令下发 1、源类 public class RemoteControl{Autowiredprivate KafkaProducer kafkaProducer;Overridepublic Boolean sendMsg(BaseRemoteRequestBean requestBean) {//业务return kafkaProducer.remoteControl(JSONObject.toJSONString(requestBean));} }2、编写适配接口 public interface AirCondAdapter {Boolean sendMsg(AirConditionRemoteRequestBean remoteRequestBean); }3、实现适配接口 //适配RemoteControlServiceImpl这个类 Service public class RemoteControlAirCondAdapter extends RemoteControlServiceImpl implements AirCondAdapter{Overridepublic Boolean sendMsg(AirConditionRemoteRequestBean remoteRequestBean) {BaseRemoteRequestBean baseRemoteRequestBeannew BaseRemoteRequestBean();BeanUtils.copyProperties(remoteRequestBean,baseRemoteRequestBean);return super.sendMsg(baseRemoteRequestBean);} }二、接口适配器模式 接口适配器适配接口 1、声明源接口 public interface RemoteControlService {Boolean sendMsg(BaseRemoteRequestBean requestBean);Boolean sendMsg(AirConditionRemoteRequestBean remoteRequestBean); }2、实现源接口 public abstract class RemoteControlServiceImpl implements RemoteControlService{Autowiredprivate KafkaProducer kafkaProducer;Overridepublic Boolean sendMsg(BaseRemoteRequestBean requestBean) {//业务return kafkaProducer.remoteControl(JSONObject.toJSONString(requestBean));}//适配这个接口public abstract Boolean sendMsg(AirConditionRemoteRequestBean remoteRequestBean); }3、适配源接口 Service public class RemoteControlAirCondAdapter extends RemoteControlServiceImpl{Overridepublic Boolean sendMsg(AirConditionRemoteRequestBean remoteRequestBean) {BaseRemoteRequestBean baseRemoteRequestBeannew BaseRemoteRequestBean();BeanUtils.copyProperties(remoteRequestBean,baseRemoteRequestBean);return super.sendMsg(baseRemoteRequestBean);} }三、对象适配器模式 对象适配器适配的是这个对象 1、适配器接口 public interface AirCondAdapter {//下发空调远控指令Boolean sendAirCondMsg(AirConditionRemoteRequestBean remoteRequestBean);//下发座椅远控指令Boolean sendSeatMsg(SeatRemoteRequestBean remoteRequestBean); }2、实现适配器 Service public class RemoteControlAirCondAdapter implements AirCondAdapter{//适配这个对象Autowiredprivate RemoteControlService remoteControlService;Overridepublic Boolean sendAirCondMsg(AirConditionRemoteRequestBean remoteRequestBean) {BaseRemoteRequestBean baseRemoteRequestBeannew BaseRemoteRequestBean();BeanUtils.copyProperties(remoteRequestBean,baseRemoteRequestBean);return remoteControlService.sendMsg(baseRemoteRequestBean);}Overridepublic Boolean sendSeatMsg(SeatRemoteRequestBean remoteRequestBean) {BaseRemoteRequestBean baseRemoteRequestBeannew BaseRemoteRequestBean();BeanUtils.copyProperties(remoteRequestBean,baseRemoteRequestBean);return remoteControlService.sendMsg(baseRemoteRequestBean);} }
http://www.yingshimen.cn/news/47359/

相关文章:

  • 企业自建网站营销论文怎么买wordpress主题
  • 网站建设前期分析做网站需要学什么
  • 合肥新站区有做网站的吗网页设计建设网站模板
  • 昆明做网站首选互维高校资源网网站建设方案
  • iis配置网站是什么培训机构官网
  • 做网站初中潍坊市奎文区建设局网站
  • 廊坊网站建设兼职网址域名ip查询
  • 建医疗网站步骤手机网站制作行业排行
  • 网站建设模板设计做英文网站多钱
  • 社交网站模板下载建网站的基本步骤
  • 邯郸的网站建设ps网页模板
  • 做网站的软件工程师seo全网营销
  • 浦东新区网站建设网站建设 图片压缩
  • 手机网站免费建站广东网站关键词排名
  • 有系统源码可以做网站吗网站左侧固定广告代码
  • 安康 住房城乡建设部网站免费文档模板下载
  • 建设银行长沙招聘网站html网页设计小作业代码部分
  • 咖啡网站建设的需求分析高端网站建设个人
  • 营口沿海开发建设有限公司网站源码猫网站建设ym361
  • 为什么网站开发这么便宜辽宁建设工程信息网查询截图
  • 网站推广seo营销培训
  • 万网关网站三次支付宝网站接口申请
  • 多网站怎么做seo笔记本做网站服务器
  • 中国住房和城乡建设部网站首页php网站进后台
  • 免费网站app代码如何撰写网站建设方案
  • 怎么上传文件到ftp网站vi系统与品牌视觉系统
  • 网站推广的特点是什么百度竞价一个月5000够吗
  • 超云建站珲春建设局网站
  • 晋城市 制作网站网页设计的模版
  • 网站建设与管理维护参考文献手机网站开发需要哪些人