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;
            }
        }
    }
  • 相关阅读:
    StringBuilder方法的使用
    软件开发一般分为五个阶段
    HTML与XML的区别(转)
    经常调用的WebServce的方法有哪些?
    1-2+3-4+........+M方法一;方法二
    查找Dom树中所有<li>的元素,并改变其内容
    判断月份是否小于10的写法
    Repeater绑定页面的方法
    转换int类型TryParse的作用
    【转】【java源码分析】Map中的hash算法分析
  • 原文地址:https://www.cnblogs.com/aaa6818162/p/1506706.html
Copyright © 2011-2022 走看看