android 设计模式: 策nue模式
来源:互联网 发布:淘宝如何进入卖家中心 编辑:程序博客网 时间:2024/05/21 13:55
这个就简单了,几句话完事
一个抽象类,提供抽象的方法。
多个具体实现,每个实现就是为了同一个目的,用了不同的实现。
具体使用时,你选则哪种实现就实例化对应的实现类,注入。
public interface CalculaterStrategy {
int caculatePrice(int km);
}
public class BusStrategy implements CalculateStrategy {
@Override
public int calculatePrice(int km) {...}
}
public class SubwayStrategy implements CalculateStrategy {
@Override
public int calculatePrice(int km) {...}
}
public class TranficCalculator {
public CalculatorStrategy mStrategy;
//具体的选择实现也就是cenue的注入
public void setStrategy(CalculateStrategy mStrategy) {
this.mStrategy = mStrategy;
}
public void caculatePrice(int km) {
return mStrategy.calculatePrice(km);
}
}
0 0
- android 设计模式: 策nue模式
- Android设计模式--适配器模式
- android设计模式--外观模式
- android设计模式-策略模式
- android设计模式-观察者模式
- android设计模式-工厂模式
- android设计模式-适配器模式
- android设计模式-组合模式
- android 设计模式 状态模式
- android 设计模式-组合模式
- Android 设计模式-----单利模式
- Android设计模式--观察者模式
- Android设计模式--适配器模式
- Android设计模式-适配器模式
- Android设计模式-适配器模式
- Android设计模式-常用模式
- [Android] 设计模式-策略模式
- Android设计模式--Builder模式
- 安卓学习笔记---自定义app顶部标题栏
- Docker常用命令
- 事务脏读,不可重复读,幻读
- 深入理解JavaScript系列(4):立即调用的函数表达式
- Unity开发Android游戏(二)Hello world!
- android 设计模式: 策nue模式
- css3动画之上下抖动
- cocos2d - JS 修改 index.html 的 title
- 第4章 处理用户输入与显示数据------------(从键盘输入的命令read,对输入计时计数)
- android-async-http ,volley ,okhttp分析
- 第二节 telnet模拟get和post方法
- 安卓 数据库的使用
- EditText 显示隐藏软键盘
- [Leetcode] 5. Longest Palindromic Substring 解题报告