工厂设计模式

 1 interface A
 2 {public void fintr();
 3 }
 4 class B implements A
 5 {public void fintr(){
 6    System.out.println("666");
 7    }
 8 }
 9 class C implements A
10 {public void fintr(){
11     System.out.println("777");
12     }
13 }
14 class D
15 {public static A getInfo(String className){
16     if ("SSS".equals(className))
17     {
18         return new B();
19     }else if ("aa".equals(className))
20     {return new C();
21     }
22     
23     
24     return null;
25   }
26 }
27 public class vvv{
28     public static void main(String args[]){
29     A a= D.getInfo(args[0]);
30       if (a != null)
31     {
32     a.fintr();
33     }
34     }
35 }

 

posted @ 2016-09-27 17:10  as145  阅读(113)  评论(0编辑  收藏  举报