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;
            }

        }
    }

  • 相关阅读:
    vue中的echarts实现宽度自适应
    前端执行vue打包后的dist文件
    nvm的使用和nrm的使用
    element-ui 中让el-container 高度自适应
    QQ登录报错:redirect uri is illegal(100010)
    纯CSS实现table固定thead,tbody进行滚动.html
    js实现垂直向上滚动
    我的 vscode 配置文件!
    CSS实现水平垂直居中的6种方式!
    百度API获取地点经纬度
  • 原文地址:https://www.cnblogs.com/kexb/p/4507671.html
Copyright © 2011-2022 走看看