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(); }
/// <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(); }
private void ShowChairInfo(IChair chair) { Console.WriteLine($"{chair.GetType().Name} has legs: {chair.HasLegs()}"); chair.SitOn(); }