•简单工程模式 功能是:选择合适的实现类。
•本质是:选择实现。
•使用的情况:
1.想完全封装隔离具体的实现。
2.想要把对外创建对象的职责集中管理和控制。
1 public interface API { 2 public void operation(String s); 3 }
public class impla implements API{ public void operation(String s){ System.out.println(s); } }
public class factory { public static API createapi(int con){ API api=null; if(con==1){ api=new impla(); } return api; } }
1 public class client { 2 public static void main(String[] args){ 3 API api=factory.createapi(1); 4 api.operation("^_^"); 5 api.operation("^_^"); 6 } 7 }
浙公网安备 33010602011771号