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;
            }
        }
    }
  • 相关阅读:
    SQL注入原理解说,非常不错!
    Asp.Netserver控件开发的Grid实现(三)列编辑器
    Windows下搭建deepnet环境
    reactor设计模式
    C++ 表达式语句 海伦的故事
    [ArcGIS必打补丁]ArcGIS 10.1 SP1 for (Desktop, Engine, Server) Quality Improvement Patch
    四个好看的CSS样式表格
    UVA 10047 The Monocycle (状态记录广搜)
    二叉搜索树相关性质的应用
    广播(broadcast)、电视与电视网络
  • 原文地址:https://www.cnblogs.com/aaa6818162/p/1506706.html
Copyright © 2011-2022 走看看