zoukankan      html  css  js  c++  java
  • 策略模式

    namespace Strategy_DesignPattern
    {
        
    using System;


        
    abstract class Strategy
        {
            
    abstract public void DoAlgorithm();
        }

        
    class FirstStrategy : Strategy
        {
            
    override public void DoAlgorithm()
            {
                Console.WriteLine(
    "In first strategy");
            }
        }

        
    class SecondStrategy : Strategy
        {
            
    override public void DoAlgorithm()
            {
                Console.WriteLine(
    "In second strategy");
            }
        }

        
    class Context
        {
            Strategy s;
            
    public Context(Strategy strat)
            {
                s 
    = strat;
            }

            
    public void DoWork()
            {
                
    // some of the context's own code goes here
            }

            
    public void DoStrategyWork()
            {
                
    // now we can hand off to the strategy to do some 
                
    // more work
                s.DoAlgorithm();
            }
        }

        
    /// <summary>
        
    ///    Summary description for Client.
        
    /// </summary>
        public class Client
        {
            
    public static int Main(string[] args)
            {
                FirstStrategy firstStrategy 
    = new FirstStrategy();
                Context c 
    = new Context(firstStrategy);
                c.DoWork();
                c.DoStrategyWork();

                
    return 0;
            }
        }
    }
  • 相关阅读:
    读书笔记:HTML5的Doctype
    2017/09/06~2017/09/10:算法练习小记
    (分治)7617:输出前k大的数
    (递归)7215:简单的整数划分问题
    (递归)2106:Boolean Expressions
    (递归)8758:2的幂次方表示
    (递归)1750:全排列
    (枚举)8469:特殊密码锁
    关于使用unigui、webxone、mysql的几个问题
    DELPHI-Delphi常用类型及定义单元
  • 原文地址:https://www.cnblogs.com/aaa6818162/p/1506706.html
Copyright © 2011-2022 走看看