using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DesignModel
{
///
/// 策略模式
///
public class TacticsModel
{
public string type { get; set; }
public virtual string GetResult()
{
return "";
}
}
public class Normal:TacticsModel
{
public override string GetResult()
{
return "正常计算价格";
}
}
public class Discount : TacticsModel
{
public override string GetResult()
{
return "按打折计算价格";
}
}
public class Preferential : TacticsModel
{
public override string GetResult()
{
return "满300减100活动";
}
}
public class CashContext
{
TacticsModel tm = null;
public CashContext(string type)
{
switch (type)
{
case "1":
tm = new Normal();
break;
case "2":
tm = new Discount();
break;
case "3":
tm = new Preferential();
break;
default:
break;
}
}
public string GetResult()
{
return tm.GetResult();
}
}
}