日期:2014-05-18 浏览次数:20816 次
public interface I { void Work(); } public class A : I { public void Work(){} } public class B : I { public void Work(){} } public class C : I { public void Work(){} } public class D : I { public void Work(){} } public class E { public static I CreateInstance() { switch(条件) { case 条件1: return new A(); case 条件2: return new B(); case 条件3: return new C(); case 条件4: return new D(); default: return null; } } } public class F { I _instance; public F() { _instance = E.CreateInstance(); } public void Work() { if(_instance != null) { _instance.Work(); } } }