AbstractMessageFactory
using System;
using System.Collections.Generic;
using System.Text;
namespace Pattern.FactoryMethod
{
/**//// <summary>
/// 抽象Message工廠(Creator)
/// </summary>
public abstract class AbstractMessageFactory
{
// An Operation
/**//// <summary>
/// 工廠方法
/// </summary>
/// <returns>AbstractMessage</returns>
public abstract AbstractMessage CreateMessage();
}
}
SqlMessageFactory
using System;
using System.Collections.Generic;
using System.Text;
namespace Pattern.FactoryMethod
{
/**//// <summary>
/// SqlMessage工廠(ConcreteCreator)
/// </summary>
public class SqlMessageFactory : AbstractMessageFactory
{
/**//// <summary>
/// 實現工廠方法,返回SqlMessage對象
/// </summary>
/// <returns></returns>
public override AbstractMessage CreateMessage()
{
return new SqlMessage();
}
}
}
XMLMessageFactory
using System;
using System.Collections.Generic;
using System.Text;
namespace Pattern.FactoryMethod
{
/**//// <summary>
/// XMLMessage工廠(ConcreteCreator)
/// </summary>
public class XMLMessageFactory : AbstractMessageFactory
{
/**//// <summary>
/// 實現工廠方法,返回XMLMessage對象
/// </summary>
/// <returns></returns>
public override AbstractMessage CreateMessage()
{
return new XMLMessage();
}
}
}