建造者模式
class Program
{
static void Main(string[] args)
{
Director director = new Director();
director.Constructor(new Benz());
director.Constructor(new BMW());
Console.ReadLine();
}
}
public interface IBuilder
{
void CreateLogo();
void CreateBody();
void CreateWheel();
void CreateChair();
}
public class Director
{
public void Constructor(IBuilder builder)
{
builder.CreateLogo();
builder.CreateBody();
builder.CreateWheel();
builder.CreateChair();
}
}
public class Benz : IBuilder
{
public void CreateLogo()
{
Console.WriteLine("创建奔驰的logo");
}
public void CreateBody()
{
Console.WriteLine("创建奔驰的身体");
}
public void CreateWheel()
{
Console.WriteLine("创建奔驰的轮子");
}
public void CreateChair()
{
Console.WriteLine("创建奔驰的椅子");
}
}
public class BMW : IBuilder
{
public void CreateLogo()
{
Console.WriteLine("创建宝马的logo");
}
public void CreateBody()
{
Console.WriteLine("创建宝马的身体");
}
public void CreateWheel()
{
Console.WriteLine("创建宝马的轮子");
}
public void CreateChair()
{
Console.WriteLine("创建宝马的椅子");
}
}