CSharp · Console
using System;
public class Program
{
public static void Main()
{
}
}
abstract class Factory
{
public abstract Product Create();
}
class FactoryA : Factory
{
public override Product Create()
{
return new ProductA();
}
}
class FactoryB : Factory
{
public override Product Create()
{
return new ProductB();
}
}
abstract class Product
{
public string Name;
}
class ProductA : Product
{
public ProductA()
{
this.Name = "Pepsi";
}
}
class ProductB : Product
{
public ProductB()
{
this.Name = "Coke";
}
}