static void FactoryTester() { #region sample 1 // use of factory creational pattern var creators = new Creator[2]; creators[0] = new ConcreteCreatorA(); creators[1] = new ConcreteCreatorB(); // Iterate over creators and create products foreach (var creator in creators) { var product = creator.FactoryMethod(); Console.WriteLine("Created {0}", product.GetType().Name); } #endregion #region sample 2 // Note: constructors call Factory Method var documents = new Document[2]; documents[0] = new Resume(); documents[1] = new Report(); // Display document pages foreach (var document in documents) { Console.WriteLine("\n" + document.GetType().Name + "--"); foreach (var page in document.Pages) { Console.WriteLine(" " + page.GetType().Name); } } #endregion }
static void Main(string[] args) { Console.WriteLine("Structural example:"); Creator[] creators = new Creator[2]; creators[0] = new ConcreteCreatorA(); creators[1] = new ConcreteCreatorB(); foreach (Creator creator in creators) { Product product = creator.FactoryMethod(); Console.WriteLine("Created {0}", product.GetType().Name); } Console.WriteLine(); Console.WriteLine("Real-world example:"); Document[] documents = new Document[2]; documents[0] = new Resume(); documents[1] = new Report(); foreach (Document document in documents) { Console.WriteLine("\n" + document.GetType().Name + "--"); foreach (Page page in document.Pages) { Console.WriteLine(" " + page.GetType().Name); } } Console.ReadKey(); }
public void CreateConcreteProductBTest() { Creator creator = new ConcreteCreatorB(); Assert.That(() => creator.AnOperation(), Throws.Exception.With.Message.EqualTo("AnOperation with object FactoryMethod.Application.ConcreteProductB type")); }
public void TestConcreteCreator() { var creators = new Creator[2]; creators[0] = new ConcreteCreatorA(); creators[1] = new ConcreteCreatorB(); Assert.AreNotEqual(creators[0].FactoryMethod().GetType().Name, creators[1].FactoryMethod().GetType().Name); Assert.AreSame(creators[0].FactoryMethod().GetType().BaseType, creators[1].FactoryMethod().GetType().BaseType); }
private void RunFactoryMethodTest() { Creator creator = new ConcreteCreatorA(); FactoryMethodPattern.Product Item1 = creator.FactoryMethod(); creator = new ConcreteCreatorB(); FactoryMethodPattern.Product Item2 = creator.FactoryMethod(); }
public override void run() { Creator[] creators = new Creator[2]; creators[0] = new ConcreteCreatorA(); creators[1] = new ConcreteCreatorB(); foreach (Creator creator in creators) { Product product = creator.FactoryMethod(); Console.WriteLine("Created {0}", product.GetType().Name); } }
public static void MainDemo(string[] args) { // FactoryMethod returns ProductA Creator c = new ConcreteCreatorA(); Product p = c.FactoryMethod(); Console.WriteLine("Created {0}", p); // FactoryMethod returns ProductB c = new ConcreteCreatorB(); p = c.FactoryMethod(); Console.WriteLine("Created {0}", p); }
public static void Run() { Console.WriteLine("\nFactory Method Structural Practice"); Creator[] creators = new Creator[2]; creators[0] = new ConcreteCreatorA(); creators[1] = new ConcreteCreatorB(); foreach (Creator creator in creators) { Product product = creator.FactoryMethod(); Console.WriteLine("Created {0}", product.GetType().Name); } }
static void Main(string[] args) { AbstractCreator creatorA = new ConcreteCreatorA(); IProduct productA = creatorA.FactoryMethod(); productA.Launch(); AbstractCreator creatorB = new ConcreteCreatorB(); IProduct productB = creatorB.FactoryMethod(); productB.Launch(); Console.Read(); }
public static void Main(string[] args) { Creator[] creators = new Creator[2]; creators[0] = new ConcreteCreatorA(); creators[1] = new ConcreteCreatorB(); foreach(Creator creator in creators) { Product product = creator.FactoryMethod(); Console.WriteLine("Created {0}", product.GetType().Name); } Console.Read(); }
static void TestSample() { var creators = new Creator[2]; creators[0] = new ConcreteCreatorA(); creators[1] = new ConcreteCreatorB(); foreach (var creator in creators) { Product product = creator.FactoryMethod(); Debug.WriteLine(creator.GetType().Name + " has created: " + product.GetType().Name); } Console.ReadKey(); }
private static void Test() { var creators = new Creator[2]; creators[0] = new ConcreteCreatorA(); creators[1] = new ConcreteCreatorB(); foreach (var creator in creators) { var product = creator.FactoryMethod(); Console.WriteLine("Created {0}", product.GetType().Name); } Console.ReadKey(); }
public static void Demo() { // An array of creators Creator[] creators = new Creator[2]; creators[0] = new ConcreteCreatorA(); creators[1] = new ConcreteCreatorB(); // Iterate over creators and create products foreach (Creator creator in creators) { IProduct product = creator.FactoryMethod(); Console.WriteLine("Created {0}", product.GetType().Name); } }
/// <summary> /// Entry point into console application. /// </summary> public static void Test() { // An array of creators Creator[] creators = new Creator[2]; creators[0] = new ConcreteCreatorA(); creators[1] = new ConcreteCreatorB(); // Iterate over creators and create products foreach (Creator creator in creators) { Product product = creator.FactoryMethod(); Console.WriteLine("Created {0}", product.GetType().Name); } }
static void RunFactoryMethod() { // 工厂方法生成的产品一般是单一 Creator[] creators = new Creator[2]; creators[0] = new ConcreteCreatorA(); creators[1] = new ConcreteCreatorB(); // Iterate over creators and create products foreach (Creator creator in creators) { Product product = creator.FactoryMethod(); Console.WriteLine("Created {0}", product.GetType().Name); } }
public void FactoryTest() { // An array of creators Creator[] creators = new Creator[2]; creators[0] = new ConcreteCreatorA(); creators[1] = new ConcreteCreatorB(); // Iterate over creators and create products foreach (Creator creator in creators) { Product product = creator.FactoryMethod(); Utility.LogEntry(string.Format("Created {0}", product.GetType().Name)); } }
static void Main(string[] args) { Creator creatorOne = new ConcreteCreatorA(); Creator creatorTwo = new ConcreteCreatorB(); // Should Print Types of ABD foreach (Product p in creatorOne.Products) { Console.WriteLine(p.GetType().ToString()); } // Shoudl Print Types of CD foreach (Product p in creatorTwo.Products) { Console.WriteLine(p.GetType().ToString()); } }
internal static void Run() { Creator[] creators = new Creator[2]; creators[0] = new ConcreteCreatorA(); creators[1] = new ConcreteCreatorB(); // Iterate over creators and create products foreach (Creator creator in creators) { Product product = creator.FactoryMethod(); Console.WriteLine("Created {0}", product.GetType().Name); } Console.ReadKey(); }
// Entry point into console application. static void Main() { // An array of creators Creator[] creators = new Creator[2]; creators[0] = new ConcreteCreatorA(); creators[1] = new ConcreteCreatorB(); // Iterate over creators and create products foreach (Creator creator in creators) { Product product = creator.FactoryMethod(); Console.WriteLine("Created {0}", product.GetType().Name); } // Wait for user Console.ReadKey(); }
static void Main(string [] args) { Creater creater; Console.WriteLine("Choose product A OR B"); string action = Console.ReadLine(); if (action == "A") { creater = new ConcreteCreatorA(); creater.createProduct(); } if (action == "B") { creater = new ConcreteCreatorB(); creater.createProduct(); } }
// "Product" // "ConcreteProductA" public void TestFactoryMethodPattern() { // An array of creators var creators = new Creator[2]; creators[0] = new ConcreteCreatorA(); creators[1] = new ConcreteCreatorB(); // Iterate over creators and create products foreach (Creator creator in creators) { Product product = creator.FactoryMethod(); Console.WriteLine("Created {0}", product.GetType().Name); } // Wait for user Console.Read(); }
static void Main(string[] args) { Creator[] creators = new Creator[2]; creators[0] = new ConcreteCreatorA(); creators[1] = new ConcreteCreatorB(); foreach (Creator obj in creators) { Product product = obj.FactoryMethod(); Console.WriteLine("Created {0}", product.GetType().Name); } ConcreteCreatorA cc1 = new ConcreteCreatorA(); cc1.Method1(); ConcreteCreatorB cc2 = new ConcreteCreatorB(); cc2.Method2(); Console.ReadKey(); }