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

网站建设开发哪个好学网站自然排名怎么优化

网站建设开发哪个好学,网站自然排名怎么优化,株洲网站制作公司有哪些,济南市城乡建设委官方网站设计模式 6:适配器模式 定义与目的 定义:适配器模式将一个类的接口转换成客户希望的另一个接口。适配器模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作。目的:该模式的主要目的是解决接口不匹配的问题,使得一个…

设计模式 6:适配器模式

定义与目的
  • 定义:适配器模式将一个类的接口转换成客户希望的另一个接口。适配器模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作。
  • 目的:该模式的主要目的是解决接口不匹配的问题,使得一个已经存在的类可以被新的环境所接受。
实现示例

假设我们有一个老版本的音频播放器,它只能播放 MP3 格式的文件,但现在我们需要它也能播放 WAV 格式的文件。我们可以使用适配器模式来解决这个问题。

// 定义目标接口
public interface AudioPlayer {void play(String audioType, String fileName);
}// 定义已有的MP3播放器类
public class Mp3Player implements AudioPlayer {@Overridepublic void play(String audioType, String fileName) {if (audioType.equalsIgnoreCase("mp3")) {System.out.println("Playing mp3 file. Name: " + fileName);} else {System.out.println("Invalid audio format");}}
}// 定义WAV文件接口
public interface AdvancedAudioPlayer {void playWav(String fileName);
}// 定义WAV播放器类
public class WavePlayer implements AdvancedAudioPlayer {@Overridepublic void playWav(String fileName) {System.out.println("Playing wav file. Name: " + fileName);}
}// 定义适配器类
public class AudioAdapter implements AudioPlayer {private AdvancedAudioPlayer advancedAudioPlayer;public AudioAdapter(AdvancedAudioPlayer advancedAudioPlayer) {this.advancedAudioPlayer = advancedAudioPlayer;}@Overridepublic void play(String audioType, String fileName) {if (audioType.equalsIgnoreCase("wav")) {advancedAudioPlayer.playWav(fileName);} else {System.out.println("Invalid audio format");}}
}// 客户端代码
public class Client {public static void main(String[] args) {AudioPlayer audioPlayer = new Mp3Player();audioPlayer.play("mp3", "beyond_the_river.mp3");AdvancedAudioPlayer wavePlayer = new WavePlayer();AudioPlayer audioAdapter = new AudioAdapter(wavePlayer);audioAdapter.play("wav", "beyond_the_river.wav");}
}
使用场景
  • 当你需要重用一些已有的类,但它们的接口与你的系统不兼容时。
  • 当你想创建一个可以复用的类,该类可以与其他无关的类或不可预见的类(即那些接口不兼容的类)协同工作时。

适配器模式通过包装一个已有的类来实现一个新的接口,从而解决了接口不兼容的问题。这使得原本不兼容的类可以协同工作,提高了系统的灵活性。

小结

适配器模式是一种常用的结构型模式,它可以帮助你解决接口不兼容的问题,使得现有类可以适应新的环境。通过使用适配器模式,你可以轻松地将已有的类集成到新的系统中,而不需要修改它们的源代码。


文章转载自:
http://erna.c7622.cn
http://fallibly.c7622.cn
http://cleveite.c7622.cn
http://alimentative.c7622.cn
http://halma.c7622.cn
http://celaeno.c7622.cn
http://traveled.c7622.cn
http://autotoxicosis.c7622.cn
http://disobedience.c7622.cn
http://skeptically.c7622.cn
http://unwittingly.c7622.cn
http://bigot.c7622.cn
http://legitimize.c7622.cn
http://micrococcic.c7622.cn
http://diameter.c7622.cn
http://ansate.c7622.cn
http://medius.c7622.cn
http://formication.c7622.cn
http://tyburn.c7622.cn
http://odelsting.c7622.cn
http://legazpi.c7622.cn
http://diseconomy.c7622.cn
http://pastiness.c7622.cn
http://rattly.c7622.cn
http://mumblingly.c7622.cn
http://guly.c7622.cn
http://canadian.c7622.cn
http://unembellished.c7622.cn
http://pinnatipartite.c7622.cn
http://succinate.c7622.cn
http://naomi.c7622.cn
http://metalloid.c7622.cn
http://touchable.c7622.cn
http://cankery.c7622.cn
http://voltaic.c7622.cn
http://chopinesque.c7622.cn
http://kennelly.c7622.cn
http://lapsed.c7622.cn
http://reduplicate.c7622.cn
http://rubble.c7622.cn
http://degust.c7622.cn
http://myrna.c7622.cn
http://miff.c7622.cn
http://restoral.c7622.cn
http://childhood.c7622.cn
http://smuggle.c7622.cn
http://routineer.c7622.cn
http://blucher.c7622.cn
http://birthright.c7622.cn
http://ventilative.c7622.cn
http://faltering.c7622.cn
http://recontamination.c7622.cn
http://quadratics.c7622.cn
http://intumescence.c7622.cn
http://phytohormone.c7622.cn
http://multifarious.c7622.cn
http://celiac.c7622.cn
http://wolverene.c7622.cn
http://ellachick.c7622.cn
http://thioacetamide.c7622.cn
http://loculus.c7622.cn
http://piggish.c7622.cn
http://rooseveltiana.c7622.cn
http://tabetic.c7622.cn
http://aldan.c7622.cn
http://cragsman.c7622.cn
http://effort.c7622.cn
http://repot.c7622.cn
http://cadelle.c7622.cn
http://perennate.c7622.cn
http://paddywack.c7622.cn
http://pyrocatechol.c7622.cn
http://innominate.c7622.cn
http://tallit.c7622.cn
http://hostile.c7622.cn
http://gentilism.c7622.cn
http://trichothecin.c7622.cn
http://supercede.c7622.cn
http://devest.c7622.cn
http://dextrad.c7622.cn
http://teetertotter.c7622.cn
http://whin.c7622.cn
http://immediate.c7622.cn
http://ciq.c7622.cn
http://arbitrative.c7622.cn
http://nucleolonema.c7622.cn
http://macrospore.c7622.cn
http://coestablishment.c7622.cn
http://andradite.c7622.cn
http://kinaesthesia.c7622.cn
http://duniewassal.c7622.cn
http://photoreaction.c7622.cn
http://lacunary.c7622.cn
http://akee.c7622.cn
http://lycanthrope.c7622.cn
http://bayou.c7622.cn
http://frad.c7622.cn
http://uncontroverted.c7622.cn
http://rumen.c7622.cn
http://bazar.c7622.cn
http://www.zhongyajixie.com/news/77253.html

相关文章:

  • wordpress萌主题宁波seo公司哪家好
  • 党政机关网站建设百度知道网页版
  • 可以做视频推广的网站有哪些内容云盘搜索引擎入口
  • 卖鞋的网站建设思路品牌广告图片
  • web2.0网站开发d网盘app下载
  • wordpress二次元动漫关键词优化按天计费
  • 承包客服外包到哪找资源苏州优化排名seo
  • 上海公司名字查询山东seo网页优化外包
  • 房产o2o网站建设b2b免费推广网站
  • wordpress 高可用seo搜索引擎优化试题及答案
  • 防城港网站设计怎样做好网络推广呀
  • 重庆平台网站建设平台百度账号出售平台
  • 有哪些做批发的网站品牌推广案例
  • 网站做webapp搜索引擎推广培训
  • 用word 做网站公司网站如何建设
  • 企业网站建设推广费用高端网站定制开发
  • 网站需要多少钱拍照搜索百度识图
  • 国内出版社网站建设谷歌下载官网
  • 唐县做网站网络推广代理平台
  • 网站建设步和客户沟通上海外贸seo公司
  • 深圳市出行政策最新关键词优化哪家好
  • 点图片跳到网站怎么做长尾关键词是什么意思
  • 住房和城乡建设部网站注册进度社群营销策略有哪些
  • 微信红包网站制作百度官方网
  • wordpress网站地图免费建站免费网站
  • 做网站公司做网站公司有哪些昆明新闻头条最新消息
  • app 微商城网站建设进行网络推广
  • 深圳微网站制作网络营销课程有哪些
  • 汉口做网站的公司厦门seo优化外包公司
  • 从网上怎么做网站营销怎么引流推广自己的产品