zoukankan      html  css  js  c++  java
  • 责任链

    1:意图
    为解除请求的发送者和接收者之间耦合,而使多个对象都有机会处理这个请求。将这些对象连成一条链,并沿着这条链传递该请求,直到有一个对象处理它。
    2:类图

    3:代码
    namespace Bll.ChainOfResponsibility
    {
        
    public class MSGEntity
        
    {
            
    //信息内容
            private string content;
            
    public string Content
            
    {
                
    get return content; }
                
    set { content = value; }
            }


            
    //审核级别
            private int level = 0;
            
    public int Level
            
    {
                
    get return level; }
                
    set { level = value; }
            }

        }

        
        
    public abstract class Man
        
    {
            
    protected Man _man;

            
    public abstract void Read(MSGEntity entity);

            
    public void SetSuccessor(Man man)
            
    {
                
    this._man = man;
            }

        }


        
    public class Employee : Man
        
    {
            
    const int level = 1;
            
    public override void Read(MSGEntity entity)
            
    {
                
    if (object.Equals(level, entity.Level))
                

                    
    //
                }

                
    else if (base._man != null)
                
    {
                    _man.Read(entity);
                }

            }

        }


        
    public class Leader : Man
        
    {
            
    const int level = 2;
            
    public override void Read(MSGEntity entity)
            
    {
                
    if (object.Equals(level, entity.Level))
                
    {
                    
    //
                }

                
    else if (base._man != null)
                
    {
                    _man.Read(entity);
                }

            }

        }


        
    public class Manage : Man
        
    {
            
    const int level = 3;
            
    public override void Read(MSGEntity entity)
            
    {
                
    if (object.Equals(level, entity.Level))
                
    {
                    
    //
                }

                
    else if (base._man != null)
                
    {
                    _man.Read(entity);
                }

            }

        }


    }

    //调用
                Employee employ = new Employee();
                Leader leader 
    = new Leader();
                Manage manage 
    = new Manage();

                employ.SetSuccessor(leader);
                leader.SetSuccessor(manage);

                employ.Read(
    new MSGEntity());
  • 相关阅读:
    摄像头距离标定方法研究(得到像素和毫米的转换比)
    mfc通过消息传递参数进行程序间通信
    基于Opencv和Mfc的图像处理增强库GOCVHelper(索引)
    【20160924】GOCVHelper MFC增强算法(4)
    【20160924】GOCVHelper 图像处理部分(3)
    Xamarin Essentials教程使用指南针Compass
    Xamarin Essentials教程使用加速度传感器Accelerometer
    XamarinSQLite教程下载安装SQLite/SQL Server Compact Toolbox
    Xamarin Essentials教程屏幕常亮ScreenLock
    Xamarin Essentials教程振动Vibration
  • 原文地址:https://www.cnblogs.com/tommyli/p/1228254.html
Copyright © 2011-2022 走看看