C#建造者模式
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SharpConsole
{
public abstract class People
{
public abstract void Display();
public abstract void ShowMsg();
}
public class Doctor : People
{
public override void Display()
{
Console.WriteLine("Doctor Display");
}
public override void ShowMsg()
{
Console.WriteLine("Doctor Display");
}
}
public class Worker : People
{
public override void Display()
{
Console.WriteLine("Worker Display");
}
public override void ShowMsg()
{
Console.WriteLine("Worker Display");
}
}
public class Director
{
private People people;
public Director(People people)
{
this.people = people;
}
public void ShowMsg()
{
people.Display();
people.ShowMsg();
}
}
class Program
{
static void Main(string[] args)
{
Worker worker = new Worker();
Doctor doctor = new Doctor();
Director director = new Director(worker);
director.ShowMsg();
director = new Director(doctor);
director.ShowMsg();
Console.Read();
}
}
}