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

        }
    }

  • 相关阅读:
    关于 CS1595 MS的知识库还是不全面,反正它给我的解决方法不能用,偶只有这样做了....
    被一贴,一个以前写的邮件发送的小类库。记住了,不是内裤
    [下载]活学活用DataGrid控件与ADO.NET
    不同浏览器透明度的写法
    通过文件读取oep值
    菜单
    CWnd::OnContextMenu函数(右键单击弹出快捷菜单)
    poj 3349(hash)
    poj 3009(dfs+回溯 模拟)
    poj 3026 (bfs+prim)
  • 原文地址:https://www.cnblogs.com/kexb/p/4507671.html
Copyright © 2011-2022 走看看