工厂方法模式(Factory Method Pattern)

工厂方法模式(Factory Method Pattern)

1.jpg.png
介绍
定义一个用于创建对象的接口,让子类决定将哪一个类实例化。Factory Method使一个类的实例化延迟到其子类。


示例
有SqlMessage和XmlMessage,用Factory Method来实例化它们。

MessageModel

http://www.cnblogs.com/Images/OutliningIndicators/None.gifusing System;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Collections.Generic;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Text;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
namespace Pattern.FactoryMethod
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif{
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif    
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif    
/// Message实体类
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif    
public class MessageModel
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif    {
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// 构造函数
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// <param name="msg">Message内容</param>
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        
/// <param name="pt">Message发布时间</param>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
public MessageModel(string msg, DateTime pt)
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        {
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif            
this._message = msg;
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif            
this._publishTime = pt;
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        }
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
private string _message;
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// Message内容
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
public string Message
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        {
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif            
get { return _message; }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif            
set { _message = value; }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        }
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
private DateTime _publishTime;
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// Message发布时间
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
public DateTime PublishTime
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        {
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif            
get { return _publishTime; }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif            
set { _publishTime = value; }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif}
http://www.cnblogs.com/Images/OutliningIndicators/None.gif


AbstractMessage

http://www.cnblogs.com/Images/OutliningIndicators/None.gifusing System;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Collections.Generic;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Text;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
namespace Pattern.FactoryMethod
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif{
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif    
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif    
/// 操作Message抽象类(Product
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif    
public abstract class AbstractMessage
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif    {
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// 获取Message
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        
/// <returns></returns>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
public abstract List<MessageModel> Get();
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// 插入Message
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// <param name="mm">Message实体对象</param>
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        
/// <returns></returns>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
public abstract bool Insert(MessageModel mm);
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif}
http://www.cnblogs.com/Images/OutliningIndicators/None.gif


SqlMessage

http://www.cnblogs.com/Images/OutliningIndicators/None.gifusing System;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Collections.Generic;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Text;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
namespace Pattern.FactoryMethod
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif{
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif    
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif    
/// Sql方式操作MessageConcreteProduct
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif    
public class SqlMessage : AbstractMessage
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif    {
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// 获取Message
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        
/// <returns></returns>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
public override List<MessageModel> Get()
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        {
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif            List<MessageModel> l = 
new List<MessageModel>();
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif            l.Add(
new MessageModel("SQL方式获取Message", DateTime.Now));
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif            
return l;
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        }
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// 插入Message
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// <param name="mm">Message实体对象</param>
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        
/// <returns></returns>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
public override bool Insert(MessageModel mm)
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        {
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif            
// 代码略
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif
            return true;
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif}
http://www.cnblogs.com/Images/OutliningIndicators/None.gif


XmlMessage

http://www.cnblogs.com/Images/OutliningIndicators/None.gifusing System;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Collections.Generic;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Text;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
namespace Pattern.FactoryMethod
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif{
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif    
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif    
/// Xml方式操作MessageConcreteProduct
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif    
public class XmlMessage : AbstractMessage
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif    {
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// 获取Message
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        
/// <returns></returns>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
public override List<MessageModel> Get()
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        {
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif            List<MessageModel> l = 
new List<MessageModel>();
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif            l.Add(
new MessageModel("XML方式获取Message", DateTime.Now));
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif            
return l;
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        }
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// 插入Message
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// <param name="mm">Message实体对象</param>
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        
/// <returns></returns>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
public override bool Insert(MessageModel mm)
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        {
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif            
// 代码略
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif
            return true;
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif}
http://www.cnblogs.com/Images/OutliningIndicators/None.gif


AbstractMessageFactory

http://www.cnblogs.com/Images/OutliningIndicators/None.gifusing System;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Collections.Generic;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Text;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
namespace Pattern.FactoryMethod
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif{
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif    
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif    
/// 抽象Message工厂(Creator
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif    
public abstract class AbstractMessageFactory
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif    {
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
// An Operation
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif

http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// 工厂方法
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        
/// <returns>AbstractMessage</returns>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
public abstract AbstractMessage CreateMessage();
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif}
http://www.cnblogs.com/Images/OutliningIndicators/None.gif


SqlMessageFactory

http://www.cnblogs.com/Images/OutliningIndicators/None.gifusing System;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Collections.Generic;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Text;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
namespace Pattern.FactoryMethod
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif{
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif    
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif    
/// SqlMessage工厂(ConcreteCreator
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif    
public class SqlMessageFactory : AbstractMessageFactory
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif    {
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// 实现工厂方法,返回SqlMessage对象
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        
/// <returns></returns>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
public override AbstractMessage CreateMessage()
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        {
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif            
return new SqlMessage();
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif}
http://www.cnblogs.com/Images/OutliningIndicators/None.gif


XmlMessageFactory

http://www.cnblogs.com/Images/OutliningIndicators/None.gifusing System;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Collections.Generic;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Text;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
namespace Pattern.FactoryMethod
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif{
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif    
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif    
/// XmlMessage工厂(ConcreteCreator
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif    
public class XmlMessageFactory : AbstractMessageFactory
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif    {
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// 实现工厂方法,返回XmlMessage对象
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        
/// <returns></returns>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
public override AbstractMessage CreateMessage()
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        {
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif            
return new XmlMessage();
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif}
http://www.cnblogs.com/Images/OutliningIndicators/None.gif



client

http://www.cnblogs.com/Images/OutliningIndicators/None.gifusing System;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Data;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Configuration;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Collections;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Web;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Web.Security;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Web.UI;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Web.UI.WebControls;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Web.UI.WebControls.WebParts;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Web.UI.HtmlControls;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using Pattern.FactoryMethod;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
public partial class FactoryMethod : System.Web.UI.Page
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif{
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif    
protected void Page_Load(object sender, EventArgs e)
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif    {
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        AbstractMessageFactory amf = 
new SqlMessageFactory();
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        AbstractMessage am = amf.CreateMessage();
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        Response.Write(am.Insert(
new MessageModel("插入", DateTime.Now)));
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        Response.Write("<br />");
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        Response.Write(am.Get()[0].Message + " " + am.Get()[0].PublishTime.ToString());
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        Response.Write("<br />");
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        amf = 
new XmlMessageFactory();
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        am = amf.CreateMessage();
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        Response.Write(am.Insert(
new MessageModel("插入", DateTime.Now)));
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        Response.Write("<br />");
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        Response.Write(am.Get()[0].Message + " " + am.Get()[0].PublishTime.ToString());
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif}
http://www.cnblogs.com/Images/OutliningIndicators/None.gif


运行结果
True
SQL方式获取Message 2007-5-4 22:34:39
True
XML方式获取Message 2007-5-4 22:34:39



果糖网