zoukankan      html  css  js  c++  java
  • 设计模式一:策略模式

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace StrategyTest
    {
        class ZhaoYun
        {
            static void Main(string[] args)
            {
                Context context;
                context = new Context(new Green());
                context.Operate();
    
                Console.Read();
            }
        }
    
        
        public interface IStrategy
        {
    
             void Operate();
        }
    
    
        class Red:IStrategy
        {
            
            public void Operate()
            {
                Console.WriteLine("Open the Red Strategy:zou hou men ");
            }
        }
    
        class Green:IStrategy
        {
    
            public void Operate()
            {
                Console.WriteLine("Open the Red Strategy:zu ji zhui bing");
            }
        }
    
        class Context
        {
            private IStrategy strategy;
    
            public  Context(IStrategy s)
            {
                this.strategy = s;
            }
    
            public void Operate()
            {
                this.strategy.Operate();
            }
        }
    }
  • 相关阅读:
    清除div中内容
    jq选中问题
    ios 笔记
    ios学习笔记01
    checkbox判断选中
    滚动条
    tooltip
    页面跳转的问题
    freemark 判断是否为空 是否存在
    构造析构与虚函数
  • 原文地址:https://www.cnblogs.com/hbhzz/p/3151870.html
Copyright © 2011-2022 走看看