namespace AbstractFactoryPatternDemo
class GamingLaptop : ILaptop
class NormalLaptop : ILaptop
class GamingDesktop : IDesktop
class NormalDesktop : IDesktop
interface IComputerFactory
ILaptop GetLaptop(string laptopType);
IDesktop GetDesktop(string desktopType);
class LenovoFactory : IComputerFactory
public ILaptop GetLaptop(string laptopType)
return new GamingLaptop();
return new NormalLaptop();
throw new ApplicationException("Not Found");
public IDesktop GetDesktop(string laptopType)
return new GamingDesktop();
return new NormalDesktop();
throw new ApplicationException("Not Found");
class DellFactory : IComputerFactory
public ILaptop GetLaptop(string laptopType)
return new GamingLaptop();
return new NormalLaptop();
throw new ApplicationException(laptopType + "type can not be created");
public IDesktop GetDesktop(string DesktopType)
return new GamingDesktop();
return new NormalDesktop();
throw new ApplicationException(DesktopType + "type can not be created");
public ComputerClient(IComputerFactory computerFactory, string computerType)
laptop = computerFactory.GetLaptop(computerType);
desktop = computerFactory.GetDesktop(computerType);
public string GetLaptopName()
public string GetDesktopName()
public static void Main()
IComputerFactory lenovoFactory = new LenovoFactory();
IComputerFactory dellFactory = new DellFactory();
Console.WriteLine("--------- Lenovo Products --------------------------");
ComputerClient lenovoClient = new ComputerClient(lenovoFactory, "Gaming");
Console.WriteLine(lenovoClient.GetLaptopName());
Console.WriteLine(lenovoClient.GetDesktopName());
lenovoClient = new ComputerClient(lenovoFactory, "Normal");
Console.WriteLine(lenovoClient.GetLaptopName());
Console.WriteLine(lenovoClient.GetDesktopName());
Console.WriteLine("--------- Dell Products --------------------------");
ComputerClient dellClient = new ComputerClient(dellFactory, "Gaming");
Console.WriteLine(dellClient.GetLaptopName());
Console.WriteLine(dellClient.GetDesktopName());
dellClient = new ComputerClient(lenovoFactory, "Normal");
Console.WriteLine(dellClient.GetLaptopName());
Console.WriteLine(dellClient.GetDesktopName());