js 适配器模式
来源:互联网 发布:电脑怎么修改淘宝评价 编辑:程序博客网 时间:2024/05/17 18:14
将一个类(对象)的接口(方法或者属性)转化成另外一个接口,以满足用户的需求,使类(对象)之间的接口不兼容问题通过适配器得以解决.
class Basketball { playBasketball () { console.log('投篮') } basketballTeam () { console.log('五个人') }}class Football { playFootball () { console.log('射门') } footballTeam () { console.log('十一个人') }}class Ball { constructor (type) { this.type = type if (type === 'football') { this.action = new Football() } else if (type === 'basketball') { this.action = new Basketball() } } play () { if (this.type === 'football') { this.action.playFootball() } else if (this.type === 'basketball') { this.action.playBasketball() } } team () { if (this.type === 'football') { this.action.footballTeam() } else if (this.type === 'basketball') { this.action.basketballTeam() } }}let ball = new Ball('football')ball.play()ball.team()let ball2 = new Ball('basketball')ball2.play()ball2.team()
阅读全文
0 0
- js之适配器模式
- js适配器模式
- Node.js 适配器模式
- js 适配器模式
- JS设计模式之适配器模式
- 【js设计模式笔记---适配器模式】
- JS设计模式——适配器模式
- JS设计模式之适配器模式
- 【js设计模式笔记---适配器模式】
- JS设计模式六:适配器模式
- 适配器(adapter)模式在JS中实践
- 适配器及适配器模式
- 适配器及适配器模式
- 适配器模式(类适配器)
- 适配器模式(默认适配器)
- 适配器模式(对象适配器)
- 适配器模式-类适配器
- 适配器模式-对象适配器
- list的简单剖析
- [免下载]Sublime Text 3 (Build 3143) 最新注册码,亲测可用!
- GraphX增加BFS测试用例
- Fiddler实现手机抓包
- 传输层-3、流水机制和滑动窗口协议
- js 适配器模式
- mybatis在xml文件中处理大于号小于号的方法
- jenkins-git下载代码超时
- Git命令大全思维导图
- Matlab 折线图转化成柱状图
- 并发编程复习(二):volatile关键字使用
- 使用Android Studio的lint清除无用的资源文件
- CoreBlueTooth 蓝牙开发相关总结
- 奖金发放