static void Main(string[] args) { Console.WriteLine("PROSTA FABRYKA"); Program p = new Program(); p.Piecz("Pizza 1"); p.Piecz("Pizza 2"); Console.WriteLine("\n\nFABRYKA ABSTRAKCYJNA"); AbstractFactory fabryka; fabryka = new AbstractFactory("HPI", new HpiFactory()); fabryka = new AbstractFactory("Traxas", new TraxasFactory()); Console.ReadKey(); }
static void Main(string[] args) { SimpleFactory.GetCook(CookName.宫保鸡丁); GBJDFactory gBJDFactory = new GBJDFactory(); gBJDFactory.Cooking(); YXRSFactory yXRSFactory = new YXRSFactory(); yXRSFactory.Cooking(); ISkinFactory skinFactory = new SpringSkinFactory(); IButton button = skinFactory.CreateButton(); ITextField textField = skinFactory.CreateTextField(); IComboBox comboBox = skinFactory.CreateComboBox(); button.Display(); textField.Display(); comboBox.Display(); Console.ReadKey(); }
private static void Main() { var productCategory = ShowMenu(); #region Naive implementation Product product; switch (productCategory) { case ProductCategory.Insurance: product = new InsuranceProduct(); break; case ProductCategory.Messenger: product = new GhasedakProduct(); break; case ProductCategory.IaaS: product = new ArvanCloudProduct(); break; case ProductCategory.CreditCalculation: product = new AbaciProduct(); break; case ProductCategory.Security: product = new SejelProduct(); break; default: throw new ArgumentOutOfRangeException(); } Report("Naive Method", product); #endregion #region Using SimpleFactory var productViaSimpleFactory = SimpleFactory.CreateProduct(productCategory); Report("Using SimpleFactory", productViaSimpleFactory); #endregion #region Using factory method Product productViaFactoryMethod; switch (productCategory) { case ProductCategory.Insurance: productViaFactoryMethod = new InsuranceFactory().CreateProduct(); break; case ProductCategory.Messenger: productViaFactoryMethod = new MessengerFactory().CreateProduct(); break; case ProductCategory.IaaS: productViaFactoryMethod = new IaaSFactory().CreateProduct(); break; case ProductCategory.CreditCalculation: productViaFactoryMethod = new CreditCalculationFactory().CreateProduct(); break; case ProductCategory.Security: productViaFactoryMethod = new SecurityFactory().CreateProduct(); break; default: throw new ArgumentOutOfRangeException(); } Report("Using FactoryMethod", productViaFactoryMethod); #endregion #region Using abstract factory var apf2 = new AbstractProductFactory2(new IaaSFactory()); var p2 = apf2.CreateProductInstance(); Report("Using apf2:", p2); var apf = new MessengerAbstractProductFactory(); var productViaApf = apf.CreateProductInstance(); Report("Using Abstract Factory", productViaApf); #endregion //CreateAndReportProduct(productCategory); }
public Program(SimpleFactory fabryka) { this.fabryka = fabryka; }
public Program(SimpleFactory factory) { this.factory = factory; }