zoukankan      html  css  js  c++  java
  • 职责链模式 通过管理端进行解耦

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace ConsoleApplication20
    {
        public interface IFiler
        {
            string doFilter(string str);
        }

        public class AFilter:IFiler
        {
            public string doFilter(string str)
            {
                return str.Replace("你妈的", "向你妈妈问好");
            }
        }

        public class BFilter : IFiler
        {
            public string doFilter(string str)
            {
               return  str.Replace("你舅舅的", "向你舅舅问好");
            }
        }

        public class CFilter : IFiler
        {
            public string doFilter(string str)
            {
                return str.Replace("你大爷的", "向你大爷问好");
            }
        }

        class Program
        {
            static void Main(string[] args)
            {
                //客户端处理敏感信息
                string msg = "我们都是好孩子 你妈的 你大爷的 你舅舅的";
               
                FilterChain fc=new FilterChain();
                fc.AddFilter(new AFilter()).AddFilter(new BFilter()).AddFilter(new CFilter());
                Console.WriteLine("------处理之前------");
                Console.WriteLine(msg);
                msg=fc.SetFilter(msg);
                Console.WriteLine("------处理之后------");
                Console.WriteLine(msg);
                Console.ReadKey();


            }
        }

        public class FilterChain
        {
            IList<IFiler>  fcFilers=new List<IFiler>();

            public FilterChain AddFilter(IFiler f)
            {
                fcFilers.Add(f);
                return this;
            }

            public string SetFilter(string msg)
            {
                foreach (var fc in fcFilers)
                {
                    msg=fc.doFilter(msg);
                }

                return msg;
            }

        }
    }

  • 相关阅读:
    newcoder 筱玛的迷阵探险(搜索 + 01字典树)题解
    str&repr的使用&format模板的自定义
    内置函数的补充与getattrebuit & item系列
    python几种常用模块
    面向对象的反射&动态导入模块
    面向对象的封装&定制数据类型
    面向对象的多态
    面向对象的继承
    面向对象的属性与方法
    面向对象的属性及类的增删改查
  • 原文地址:https://www.cnblogs.com/kexb/p/4507671.html
Copyright © 2011-2022 走看看