C#面向对象设计模式纵横谈——17 Mediator中介者模式

主讲:李建忠

来源:http://www.microsoft.com/china/msdn/events/webcasts/shared/webcast/consyscourse/CsharpOOD.aspx

 

clip_image002

clip_image004

clip_image006

clip_image008

 

   1:   
   2:  abstract class Mediator
   3:  {
   4:      public abstract void Notify();
   5:      public abstract void AddElement(Element element)
   6:      {
   7:          list.Add(element);
   8:      }
   9:   
  10:      ArrayList<Element> list=new ArrayList<Element>();
  11:  }
  12:   
  13:  abstract class Element
  14:  {
  15:      Mediator mediator;
  16:   
  17:      public Element(Mediator mediator)
  18:      {
  19:          this.mediator=mediator;
  20:      }
  21:   
  22:      public virtual void OnChange()
  23:      {
  24:          mediator.Notify();
  25:      }
  26:  }
  27:   
  28:  class CutMenuItem:Element
  29:  {
  30:      public CutMenuItem(Mediator mediator)
  31:          :base(mediator)
  32:      {
  33:          //...
  34:      }
  35:   
  36:      public void Click()
  37:      {
  38:          OnChange();
  39:      }
  40:  }
  41:   
  42:  class TextArea:Element
  43:  {
  44:      public TextArea(Mediator mediator)
  45:          :base(mediator)
  46:      {
  47:          //...
  48:      }
  49:   
  50:      public void Process()
  51:      {
  52:          OnChange();
  53:      }
  54:  }
  55:   
  56:  class ToolBarButton:Element
  57:  {
  58:      public ToolBarButton(Mediator mediator)
  59:          :base(mediator)
  60:      {
  61:          //...
  62:      }
  63:   
  64:      public void Click()
  65:      {
  66:          OnChange();
  67:      }
  68:  }
  69:   
  70:  class ConcreteMediator:Mediator
  71:  {
  72:      public override void Notify()
  73:      {
  74:   
  75:      }
  76:   
  77:      
  78:  }

 

clip_image010

clip_image012

clip_image014

你可能感兴趣的:(media)