[索引页]
[源码下载]


乐在其中设计模式(C#) - 状态模式(State Pattern)


作者:webabcd


介绍
允许一个对象在其内部状态改变时改变它的行为。对象看起来似乎修改了它所属的类。


示例
有一个Message实体类,对它的操作有Insert()和Get()方法,持久化数据在SqlServer数据库中或Xml文件里。在对象内部可以根据用户的不同选择不同的数据持久化方案。
乐在其中设计模式(C#) - 状态模式(State Pattern)


MessageModel
乐在其中设计模式(C#) - 状态模式(State Pattern)using System;
乐在其中设计模式(C#) - 状态模式(State Pattern)
using System.Collections.Generic;
乐在其中设计模式(C#) - 状态模式(State Pattern)
using System.Text;
乐在其中设计模式(C#) - 状态模式(State Pattern)
乐在其中设计模式(C#) - 状态模式(State Pattern)
namespace Pattern.State

AbstractMessageState
乐在其中设计模式(C#) - 状态模式(State Pattern)using System;
乐在其中设计模式(C#) - 状态模式(State Pattern)
using System.Collections.Generic;
乐在其中设计模式(C#) - 状态模式(State Pattern)
using System.Text;
乐在其中设计模式(C#) - 状态模式(State Pattern)
乐在其中设计模式(C#) - 状态模式(State Pattern)
namespace Pattern.State

XmlMessage
乐在其中设计模式(C#) - 状态模式(State Pattern)using System;
乐在其中设计模式(C#) - 状态模式(State Pattern)
using System.Collections.Generic;
乐在其中设计模式(C#) - 状态模式(State Pattern)
using System.Text;
乐在其中设计模式(C#) - 状态模式(State Pattern)
乐在其中设计模式(C#) - 状态模式(State Pattern)
namespace Pattern.State

SqlMessage
乐在其中设计模式(C#) - 状态模式(State Pattern)using System;
乐在其中设计模式(C#) - 状态模式(State Pattern)
using System.Collections.Generic;
乐在其中设计模式(C#) - 状态模式(State Pattern)
using System.Text;
乐在其中设计模式(C#) - 状态模式(State Pattern)
乐在其中设计模式(C#) - 状态模式(State Pattern)
namespace Pattern.State

Message
乐在其中设计模式(C#) - 状态模式(State Pattern)using System;
乐在其中设计模式(C#) - 状态模式(State Pattern)
using System.Collections.Generic;
乐在其中设计模式(C#) - 状态模式(State Pattern)
using System.Text;
乐在其中设计模式(C#) - 状态模式(State Pattern)
乐在其中设计模式(C#) - 状态模式(State Pattern)
namespace Pattern.State


client
乐在其中设计模式(C#) - 状态模式(State Pattern)using System;
乐在其中设计模式(C#) - 状态模式(State Pattern)
using System.Data;
乐在其中设计模式(C#) - 状态模式(State Pattern)
using System.Configuration;
乐在其中设计模式(C#) - 状态模式(State Pattern)
using System.Collections;
乐在其中设计模式(C#) - 状态模式(State Pattern)
using System.Web;
乐在其中设计模式(C#) - 状态模式(State Pattern)
using System.Web.Security;
乐在其中设计模式(C#) - 状态模式(State Pattern)
using System.Web.UI;
乐在其中设计模式(C#) - 状态模式(State Pattern)
using System.Web.UI.WebControls;
乐在其中设计模式(C#) - 状态模式(State Pattern)
using System.Web.UI.WebControls.WebParts;
乐在其中设计模式(C#) - 状态模式(State Pattern)
using System.Web.UI.HtmlControls;
乐在其中设计模式(C#) - 状态模式(State Pattern)
乐在其中设计模式(C#) - 状态模式(State Pattern)
using Pattern.State;
乐在其中设计模式(C#) - 状态模式(State Pattern)
乐在其中设计模式(C#) - 状态模式(State Pattern)
public partial class State : System.Web.UI.Page

运行结果
True
SQL方式获取Message 2007-3-6 22:58:17
True
XML方式获取Message 2007-3-6 22:58:17


参考
http://www.dofactory.com/Patterns/PatternState.aspx


OK
[源码下载]

相关文章: