static void Main()
{
AbstractFactory shandongFactory = new ShandongFactory();
Car shandongCar = shandongFactory.CreateCar();
shandongCar.Run();
Bus shandongBus = shandongFactory.CreateBus();
shandongBus.Run();
AbstractFactory beijingFactory = new BeijingFactory();
beijingFactory.CreateCar();
beijingFactory.CreateBus();
}
public abstract class AbstractFactory
{
public abstract Car CreateCar();
public abstract Bus CreateBus();
}
public class ShandongFactory : AbstractFactory
{
public override Car CreateCar()
{
return new ShandongCar();
}
public override Bus CreateBus()
{
return new ShandongBus();
}
}
public class BeijingFactory : AbstractFactory
{
public override Car CreateCar()
{
return new BeijingCar();
}
public override Bus CreateBus()
{
return new BeijingBus();
}
}
public abstract class Car
{
public abstract void Run();
}
public abstract class Bus
{
public abstract void Run();
}
public class ShandongCar : Car
{
public abstract void Run()
{
MessageBox.Show("Shandong Car");
}
}
public class ShandongBus : Bus
{
public abstract void Run()
{
MessageBox.Show("Shandong Bus");
}
}
public class BeijingCar : Car
{
public abstract void Run()
{
MessageBox.Show("Being Car");
}
}
public class BeijingBus : Bus
{
public abstract void Run()
{
MessageBox.Show("BeijingBus");
}
}
}