Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Action action;
            string actionLink = "https://en.wikipedia.org/wiki/Assassination_of_John_F._Kennedy";
            string date       = "22.11.1963";

            Console.WriteLine("Enter what leng u want");
            Console.WriteLine("1. Ukraine description\n2. English description");
            int n = int.Parse(Console.ReadLine());

            if (n == 1)
            {
                action = new ConcreteCreator1(date, actionLink);
            }
            else
            {
                action = new ConcreteCreator2(date, actionLink);
            }

            IProduct productPrint = action.Print();
            IProduct product      = action.GetDescription();

            Console.WriteLine(product.GetDescriptions());
            Console.WriteLine(productPrint);
        }
        static void Main(string[] args)
        {
            //This is just an example to show how to create concrete product objects with the FactoryMethod

            ConcreteCreator1 creatorObject = new ConcreteCreator1();

            //A call to an inherited method
            creatorObject.SomeMethod();

            //A call to a specific Concrete Creator1 method
            creatorObject.SpecificConcreteCreator1Method();


            ConcreteProduct1 concreteProduct1 = (ConcreteProduct1)creatorObject.FactoryMethod();

            concreteProduct1.Method1();
            concreteProduct1.SpecificConcreteProduct1Method();
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello Factory Method!");

            Client client = new Client();

            Console.WriteLine("App: Launched with the ConcreteCreator1.");
            Creator creator1 = new ConcreteCreator1();

            client.ClientCode(creator1);

            Console.WriteLine();

            Console.WriteLine("App: Launched with the ConcreteCreator2.");
            Creator creator2 = new ConcreteCreator2();

            client.ClientCode(creator2);

            Console.ReadLine();
        }