static void Main(string[] args) { LeiFeng studentA = SimpleFactory.CreateLeiFeng("学雷锋的大学生"); studentA.Sweep(); LeiFeng studentB = SimpleFactory.CreateLeiFeng("学雷锋的大学生"); studentB.Wash(); LeiFeng volunteer = SimpleFactory.CreateLeiFeng("社区志愿者"); volunteer.BuyRice(); Console.ReadLine(); }
public static LeiFeng CreateLeiFeng(string type) { LeiFeng result = null; switch (type) { case "学雷锋的大学生": result = new Undergraduate(); break; case "社区志愿者": result = new Volunteer(); break; } return(result); }