您的位置:首页 > 编程语言 > C#

乐在其中设计模式(C#) - 访问者模式(Visitor Pattern)

2007-05-27 15:04 741 查看
[索引页]

[源码下载]

[align=center]乐在其中设计模式(C#) - 访问者模式(Visitor Pattern)[/align]

作者:webabcd

介绍

表示一个作用于某对象结构中的各元素的操作。它使你可以在不改变各元素的类的前提下定义作用于这些元素的新操作。

示例

有一个Message实体类,某些对象对它的操作有Insert()和Get()方法,现在要针对其中某一方法进行操作。

using System;

using System.Collections.Generic;

using System.Text;

namespace Pattern.Visitor

AbstractElement

using System;

using System.Collections.Generic;

using System.Text;

namespace Pattern.Visitor

Message

using System;

using System.Collections.Generic;

using System.Text;

namespace Pattern.Visitor

SqlMessage

using System;

using System.Collections.Generic;

using System.Text;

namespace Pattern.Visitor

XmlMessage

using System;

using System.Collections.Generic;

using System.Text;

namespace Pattern.Visitor

AbstractVisitor

using System;

using System.Collections.Generic;

using System.Text;

namespace Pattern.Visitor

InsertVisitor

using System;

using System.Collections.Generic;

using System.Text;

namespace Pattern.Visitor

GetVisitor

using System;

using System.Collections.Generic;

using System.Text;

namespace Pattern.Visitor

Messages

using System;

using System.Collections.Generic;

using System.Text;

namespace Pattern.Visitor

Test

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using Pattern.Visitor;

public partial class Visitor : System.Web.UI.Page

运行结果

True

True

SQL方式获取Message 2007-5-27 15:01:53

XML方式获取Message 2007-5-27 15:01:53

参考

http://www.dofactory.com/Patterns/PatternVisitor.aspx

OK

[源码下载]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: