using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _019策略模式
{
public interface Solution
{
void Method();
}
public class Solution1 : Solution
{
public void Method()
{
Console.WriteLine("解决方案1");
}
}
public class Solution2 : Solution
{
public void Method()
{
Console.WriteLine("解决方案2");
}
}
public class Solution3 : Solution
{
public void Method()
{
Console.WriteLine("解决方案3");
}
}
public class Context
{
private Solution solution;
public Context(Solution s)
{
this.solution = s;
}
public void Solute()
{
solution.Method();
}
}
internal class Program
{
private static void Main(string[] args)
{
Context context = new Context(new Solution2());
context.Solute();
/*
* 策略模式
*
* 通过实现不同的接口,基类来达到策略目的
*
*/
Console.ReadKey();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _019策略模式
{
public interface Solution
{
void Method();
}
public class Solution1 : Solution
{
public void Method()
{
Console.WriteLine("解决方案1");
}
}
public class Solution2 : Solution
{
public void Method()
{
Console.WriteLine("解决方案2");
}
}
public class Solution3 : Solution
{
public void Method()
{
Console.WriteLine("解决方案3");
}
}
public class Context
{
private Solution solution;
public Context(Solution s)
{
this.solution = s;
}
public void Solute()
{
solution.Method();
}
}
internal class Program
{
private static void Main(string[] args)
{
Context context = new Context(new Solution2());
context.Solute();
/*
* 策略模式
*
* 通过实现不同的接口,基类来达到策略目的
*
*/
Console.ReadKey();
}
}
}