order.Execute();
}
orderList.Clear();
}
}
}
解释器模式:就是实现一种表达式接口,C#的各种表达式就是这种实现吧··这玩意跟富文本编辑器一样是个大坑吧··,做好了
确实很好使,一不小心就得跪
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//解释器模式
namespace ExercisePrj.Dsignmode
{
public interface Expression
{
bool Interpret(string context);
}
public class TerminalExpression : Expression
{
private string data;
public TerminalExpression(string data)
{
this.data = data;
}
public bool Interpret(string context)
{
if (context.Contains(data))
{
return true;
}
return false;
}
}
public class OrExpression : Expression
{
private Expression expr1 = null;
private Expression expr2 = null;
public OrExpression(Expression expr1, Expression expr2)
{
this.expr1 = expr1;
this.expr2 = expr2;
}
public bool Interpret(String context)
{
return expr1.Interpret(context) || expr2.Interpret(context);
}
}
public class AndExpression : Expression
{
private Expression expr1 = null;
private Expression expr2 = null;
public AndExpression(Expression expr1, Expression expr2)
{
this.expr1 = expr1;
this.expr2 = expr2;
}
public bool Interpret(String context)
{
return expr1.Interpret(context) && expr2.Interpret(context);
}
}
}
迭代器模式(Iterator Pattern):.NET自带接口···,直接实现就行了··注意又泛型接口和非泛型接口··非泛型接口迭代对象返回
的是object,泛型接口返回的直接就是对象了,还有通过yield的简化写法不用额外去实现IEnumerator接口
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;