static void main(string[] args) { ILeiFengFactory factory = new UndergraduateFactory(); LeiFeng student = factory.CreateLeiFeng(); student.BuyRice(); student.Sweep(); student.Wash(); }
static void main(string[] args) { LeiFeng studentA = SimpleFactory.CreateLeiFeng("Undergraduate"); studentA.BuyRice(); LeiFeng studentB = SimpleFactory.CreateLeiFeng("Undergraduate"); studentB.Sweep(); LeiFeng studentC = SimpleFactory.CreateLeiFeng("Undergraduate"); studentC.Wash(); }
public static LeiFeng CreateLeiFeng(string type) { LeiFeng result = null; switch (type) { case "Undergraduate": result = new Undergraduate(); break; case "Volunteer": result = new Volunteer(); break; } return(result); }