zoukankan      html  css  js  c++  java
  • Mediator 中介者模式

    public abstract class Element
        {
            protected Mediator mediator;
    
            public Element( Mediator mediator )
            {
                this.mediator = mediator;
                this.mediator.AddElement( this );
            }
    
            public virtual void OnChange()
            {
                mediator.Notify();
            }
        }
    public abstract class Mediator
        {
            IList<Element> list;
    
            public abstract void Notify();
            public virtual void AddElement( Element element )
            {
                if( list == null )
                {
                    list.Add( element );
                }
            }
        }
    public class ClipBorad:Element
        {
            public ClipBorad( Mediator mediator )
                : base( mediator )
            {
            }
    
            public void Invoke()
            {
                OnChange();
            }
        }
      public class ConcreteMediator:Mediator
        {
            public override void Notify()
            {
            }
        }
    public class CutMenuItem:Element
        {
            public CutMenuItem( Mediator mediator )
                : base( mediator )
            {
            }
    
            public void Click()
            {
                mediator.Notify();
            }
        }
        public class TextArea:Element
        {
            public TextArea( Mediator mediator )
                : base( mediator )
            {
            }
    
            public void Process()
            {
                mediator.Notify();
            }
        }
     public class ToolBarButton:Element
        {
            public ToolBarButton( Mediator mediator )
                : base( mediator )
            {
            }
    
            public void Click()
            {
                OnChange();
            }
        }
  • 相关阅读:
    python set()、len()、type()、保留小数、EOFError
    代码学习与感悟
    你的代码的风格
    python 面向对象的类
    ubuntu 上下左右键变成ABCD
    python运算符
    python 数据类型详解
    python关键字
    python 设计及调试的一些小技巧
    python-list
  • 原文地址:https://www.cnblogs.com/wangchuang/p/3014389.html
Copyright © 2011-2022 走看看