策略模式(简单例子)
public class huanjing {sageInter sage; public sageInter getSage() {return sage;}public void setSage(sageInter sage) {this.sage = sage;}public huanjing(sageInter sage){ this.sage=sage; }}
?环境类
public interface sageInter { public int come(int a,int b);}
?接口
public class chu implements sageInter {@Overridepublic int come(int a, int b) {// TODO Auto-generated method stubreturn 1/b;}}
?实现类
public static void main(String[] args) {// TODO Auto-generated method stub jian j=new jian(); huanjing hj=new huanjing(j); int s= hj.getSage().come(10, 11); System.out.println(s);}
?调用类