using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StrategyPattern
{
///
/// 旅行策略类
///
public abstract class TravelStrategy
{
///
/// 目的地
///
public string PlanName { get; set; }
///
/// 预算
///
public int Budget { get; set; }
///
/// 旅游计划
///
public abstract void TravelPlan();
}
public class GuangxiTravel : TravelStrategy
{
public GuangxiTravel()
{
this.PlanName = "广西桂林山水甲天下,心向往之!";
}
public override void TravelPlan()
{
Console.WriteLine("广西旅游计划:");
Console.WriteLine(string.Format("计划名称:{0}预算:{1}", this.PlanName, this.Budget));
if (this.Budget >= 4000)
{
Console.WriteLine("选择高铁出行!");
}
else
{
Console.WriteLine("选择大巴出行!");
}
}
}
public class BackupTravel : TravelStrategy
{
public BackupTravel()
{
this.PlanName = "逛街看电影包饺子!";
}
public override void TravelPlan()
{
Console.WriteLine("备用计划:");
Console.WriteLine(string.Format("计划名称:{0}", this.PlanName));
}
}
}