设计模式:访问者模式与观察者模式解析
1. 访问者模式
访问者模式允许在不修改现有架构的情况下添加新功能。以下是一个简单的访问者模式示例:
using System;
namespace VisitorPattern
{
interface IOriginalInterface
{
void Accept(IVisitor visitor);
}
class MyClass : IOriginalInterface
{
private int myInt = 5;
public int MyInt
{
get
{
return myInt;
}
set
{
myInt = value;
}
}
public void Accept(IVisitor visitor)
{
Console.WriteLine("Initial value of the integer:{0}", myInt);
visitor.Visit(this);
Console.WriteLine("\nValue of the integer now:{0}", myInt);
}
}
interface IV
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



