示例#1
0
            public static string[] Run(IFurnitureFactory factory)
            {
                var chair1 = factory.CreateChair();
                var chair2 = factory.CreateChair();
                var table  = factory.CreateTable();


                return(new[] {
                    $"Price for chair1: {chair1.Price}",
                    $"Price for chair2: {chair2.Price}",
                    $"Price for table: {table.Price}",
                    $"Number of chairs to get discount: {table.NrOfChairsToGetDiscount}",
                    $"Price for table with chair1 and chair2: {(int)table.PriceWithChairs(chair1,chair2)}"
                });
            }
        /// <summary>
        /// Simulates the client code only knowing it gets a Factory.
        /// Probably some service/handler that gets injected with the IFurnitureFactory
        /// but does not know what implementation types
        /// </summary>
        private static void DescribeChair(IFurnitureFactory factory)
        {
            IChair chair = factory.CreateChair();

            chair.SitOn();
            chair.HasLegs();
        }
        public void ClientMethod(IFurnitureFactory furnitureFactory)
        {
            var productA = furnitureFactory.CreateChair();
            var productB = furnitureFactory.CreateSofa();

            System.Console.WriteLine(productA.UseFullFunction());
        }
示例#4
0
        public void ClientMethod(IFurnitureFactory factory)
        {
            var chair = factory.CreateChair();
            var sofa  = factory.CreateSofa();

            Console.WriteLine(sofa.Type());
            Console.WriteLine(sofa.Print(chair));
        }
示例#5
0
        static void CreateFurniture(IFurnitureFactory factory)
        {
            factory.CreateChair().ShowInfo();
            factory.CreateSofa().ShowInfo();
            factory.CreateTable().ShowInfo();

            Console.WriteLine();
        }
示例#6
0
        private static void CreateFurniture(IFurnitureFactory factory)
        {
            var chair = factory.CreateChair();
            var sofa  = factory.CreateSofa();
            var table = factory.CreateTable();

            chair.PrintInfo();
            sofa.PrintInfo();
            table.PrintInfo();
        }
        static void RunApplication(IFurnitureFactory factory)
        {
            var chair = factory.CreateChair();
            var sofa  = factory.CreateSofa();

            WriteLine($"This chair has{(chair.HasLegs() ? "": " not")} legs");
            WriteLine($"This sofa has{(sofa.HasLegs() ? "" : " not")} legs");

            chair.SeatOn();
            sofa.SeatOn();

            ReadLine();
        }
示例#8
0
        public static void ClientMethod(IFurnitureFactory factory)
        {
            Console.WriteLine($"---------------Order in {factory}---------------");
            var chair = factory.CreateChair();

            chair.hasLegs();
            chair.sitOn();
            var sofa = factory.CreateSofa();

            sofa.hasBack();
            sofa.hasLegs();
            sofa.lieOn();
            sofa.sitOn();
        }
        private void ClientMethod(IFurnitureFactory factory)
        {
            var chair = factory.CreateChair();

            _testOutputHelper.WriteLine(chair.SittingOnChair());

            var sofa = factory.CreateSofa();

            _testOutputHelper.WriteLine(sofa.SittingOnSofa());

            var coffeeTable = factory.CreateCoffeeTable();

            _testOutputHelper.WriteLine(coffeeTable.UseTable());
        }
示例#10
0
        private static void PrintSelectedCollectionDetails(IFurnitureFactory furnitureFactory, string selectedCollection)
        {
            var chair       = furnitureFactory.CreateChair();
            var coffeeTable = furnitureFactory.CreateCoffeeTable();
            var sofa        = furnitureFactory.CreateSofa();

            Console.WriteLine($"***** collection name: {selectedCollection} *****");
            Console.WriteLine($"Chair{Environment.NewLine}" +
                              $"Design: {chair.Design} {Environment.NewLine}" +
                              $"Construction: {chair.Construction} {Environment.NewLine}");

            Console.WriteLine($"Coffee Table{Environment.NewLine}" +
                              $"Design: {coffeeTable.Design} {Environment.NewLine}" +
                              $"Construction: {coffeeTable.Construction} {Environment.NewLine}");

            Console.WriteLine($"Sofa{Environment.NewLine}" +
                              $"Design: {sofa.Design} {Environment.NewLine}" +
                              $"Construction: {sofa.Construction} {Environment.NewLine}");
        }
示例#11
0
 public Factory(IFurnitureFactory factory)
 {
     _bed   = factory.CreateBed();
     _chair = factory.CreateChair();
 }
示例#12
0
 public Client(IFurnitureFactory factory)
 {
     Chair = factory.CreateChair();
     Table = factory.CreateTable();
 }