Beispiel #1
0
 public bool Execute(CLIBase parent, CliCommand Input)
 {
     switch (Input.Command)
     {
     case "transport":
         if (Input.Count > 1)
         {
             if (int.TryParse(Input[0], out int nPassengers) && int.TryParse(Input[1], out int distance))
             {
                 ITransportFactory f = new ComplexFactory();
                 Console.WriteLine(f.SelectBest(nPassengers, distance)?.Name ?? "No transport");
                 return(true);
             }
         }
         break;
     }
     return(false);
 }
Beispiel #2
0
        static void AbstractFactoryExample(int exampleNumber)
        {
            Console.WriteLine("Abstract Factory Example");

            IFactory factory;

            if (exampleNumber % 2 == 0)
            {
                factory = new SimpleFactory();
            }
            else
            {
                factory = new ComplexFactory();
            }

            var item = factory.GetItem();

            item.DoStuff();

            var otherItem = factory.GetOtherItem();

            otherItem.Sell(10);
        }