using System;
using System.Configuration;
namespace Builder
{
public abstract class House
{
}
public abstract class Windows
{
}
public abstract class Wall
{
}
public abstract class Floor
{
}
public abstract class HouseCeiling
{
}
public abstract class Builder
{
public abstract void BuilderDoor();
public abstract void BuildWindows();
public abstract void BuildWall();
public abstract void BuildFloor();
public abstract void BuildHouseCeiling();
public abstract House GetHouse();
}
/// <summary>
/// ///////////////////////////////////////////////////////
/// </summary>
public class RomainHouse:House
{
}
public class RomainWindows:Windows
{
}
public class RomainWall:Wall
{
}
public class RomainFloor:Floor
{
}
public class RomainHouseCeiling:HouseCeiling
{
}
public class RomainBuilder:Builder
{
public override void BuilderDoor()
{
}
public override void BuildWindows()
{
}
public override void BuildWall()
{
}
public override void BuildFloor()
{
}
public override void BuildHouseCeiling()
{
}
public override House GetHouse()
{
return new RomainHouse();
}
}
/// <summary>
/// /////////////////////////////////////////////////////////////////////////////////
/// 不变的主线
/// </summary>
public class GameManager
{
public static House CreateHouse(Builder builder)
{
builder.BuilderDoor();
builder.BuilderDoor();
builder.BuildWall();
builder.BuildWall();
builder.BuildWindows();
builder.BuildWindows();
builder.BuildHouseCeiling();
builder.BuildFloor();
return builder.GetHouse();
}
}
public class Test
{
/// <summary>
/// 用到了动态特指
/// </summary>
public static void Main()
{
House house;
string builderName,assemblyName;
assemblyName=System.Configuration.ConfigurationSettings.AppSettings["AssemblyName"];
builderName=System.Configuration.ConfigurationSettings.AppSettings["BuilderName"];
System.Reflection.Assembly assembly = System.Reflection.Assembly.Load(assemblyName);
Type t=assembly.GetType(builderName);
Builder builder=(Builder)System.Activator.CreateInstance(t);
house=GameManager.CreateHouse(builder);
}
}
}