using System;
public interface Color
{
string GetNameColor();
}
public class WhiteColor : Color
{
public string GetNameColor() => "White";
}
public class YellowColor : Color
{
public string GetNameColor() => "Yellow";
}
public interface Material
{
string GetMaterialType();
}
public class WoodMaterial : Material
{
public string GetMaterialType() => "Wood";
}
public class MetalMaterial : Material
{
public string GetMaterialType() => "Metal";
}
// Abstract Factory
public interface IColorFactory
{
Color GetColor();
Material GetMaterial();
}
// Factory cho khu vực châu Á
public class AsianColorFactory : IColorFactory
{
public Color GetColor()
{
return new WhiteColor();
}
public Material GetMaterial()
{
return new WoodMaterial();
}
}
// Factory cho khu vực châu Âu
public class EuropeColorFactory : IColorFactory
{
public Color GetColor()
{
return new YellowColor();
}
public Material GetMaterial()
{
return new MetalMaterial();
}
}
// Sử dụng Abstract Factory
public class PaintProduction
{
private static void ProducePaint(IColorFactory factory)
{
Color color = factory.GetColor();
Material material = factory.GetMaterial();
Console.WriteLine($"Producing paint of color: {color.GetNameColor()} using {material.GetMaterialType()} material.");
}
public static void Main(string[] args)
{
IColorFactory asianFactory = new AsianColorFactory();
ProducePaint(asianFactory);
IColorFactory europeFactory = new EuropeColorFactory();
ProducePaint(europeFactory);
}
}