コード例 #1
0
        static void Main(string[] args)
        {
            // Modern things

            IFurnitureFactory furnitureFactory = new ModernFurnitureFactory();

            IChair chair = furnitureFactory.CreateChair();
            ITable table = furnitureFactory.CreateCoffeeTable();

            chair.HasLegs();
            chair.SitOn();

            table.Shape();
            table.SitNextTo();

            // Viktorian things

            furnitureFactory = new ViktorianFurnitureFactory();

            chair = furnitureFactory.CreateChair();
            table = furnitureFactory.CreateCoffeeTable();

            chair.HasLegs();
            chair.SitOn();

            table.Shape();
            table.SitNextTo();
        }
コード例 #2
0
        /// <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();
        }
コード例 #3
0
 private void ShowChairInfo(IChair chair)
 {
     Console.WriteLine($"{chair.GetType().Name} has legs: {chair.HasLegs()}");
     chair.SitOn();
 }