【设计模式篇】Android设计模式之-策略模式 自我见解
来源:互联网 发布:js 解压缩 编辑:程序博客网 时间:2024/04/30 20:15
Android策略模式,主要有3个部分,算法抽象接口,一个上下文对象,具体算法三个部分
抽象接口实现一些公用的共有的方法。
上下文对象,对具体的方法进行,回调处理。这里面是面向接口编程。来切换对应的算法
具体算法,是实现与抽象的接口。
package com.ferris.strategy;/** * 算法的接口,通过上下文来调用具体的策略实现方法 * @author Administrator * */public interface BaseStrategy {public int daohang(int daohangfangshi);}
package com.ferris.strategy;public class BikeSrategy implements BaseStrategy {@Overridepublic int daohang(int daohangfangshi) {// TODO Auto-generated method stubreturn 0;}}
package com.ferris.strategy;public class WalkStrategy implements BaseStrategy{@Overridepublic int daohang(int daohangfangshi) {// TODO Auto-generated method stubreturn 0;}}
package com.ferris.strategy;public class ContextStrategy {/** * 设置策略,切换一个新的策略 */private BaseStrategy strategy;public BaseStrategy getStrategy() {return strategy;}public void setStrategy(BaseStrategy strategy) {this.strategy = strategy;}public void CalBaseSrategy(int index){if(strategy!=null&&strategy instanceof BaseStrategy){strategy.daohang(index); //切换对应的算法}}}
0 0
- 【设计模式篇】Android设计模式之-策略模式 自我见解
- 【设计模式篇】Android设计模式之-组合模式 自我见解
- 【设计模式篇】Android设计模式之-观察者模式 自我见解
- android设计模式之策略模式
- Android 设计模式之策略模式
- Android 设计模式之策略模式
- Android设计模式之策略模式
- Android设计模式之策略模式
- Android设计模式之策略模式
- Android 常用设计模式之 -- 策略模式
- Android 设计模式之策略模式
- 设计模式之个人见解
- 设计模式之见解一
- 设计模式之见解二
- 设计模式之见解三
- 设计模式之策略模式
- 设计模式之策略模式
- 设计模式之策略模式
- 上众筹,智能手环走“全民路线”破局?
- rac_第二个节点重启后无法启动实例:磁盘组dismount问题
- android 2.3 & 4.2 Audio静音过程分析
- Linux内核调试:vmdumper <world-id> nmi,死循环调试
- 发的患过伤风的故事发生的
- 【设计模式篇】Android设计模式之-策略模式 自我见解
- 计算机基础知识的学习与巩固
- 自定义View小练习
- POJ 2528 解题报告
- 苏州安仁信息科技有限公司
- 十、多线程
- 国务院再取消67项职业资格许可和认定事项
- ifeng code relax jquery main page phone Version2
- 同事写的当webview里有视频时 横屏观看后状态栏异常的处理方法