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;
            }
        }
    }
  • 相关阅读:
    三范式最简单最易记的解释
    Mysql添加用户错误:ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value解决方法
    mysql体系结构管理
    mysql的简单操作
    flush privileges刷新MySQL的系统权限相关表
    二进制安装mysql
    扩展一台mysql-5.6.40
    mysql5.6.40部署过程
    三剑客-awk
    三剑客-sed
  • 原文地址:https://www.cnblogs.com/aaa6818162/p/1506706.html
Copyright © 2011-2022 走看看