博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
一个模式
阅读量:6242 次
发布时间:2019-06-22

本文共 7527 字,大约阅读时间需要 25 分钟。

控制器

1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5  6 namespace RGeos.FrameWork.MVC 7 { 8     //控制类 9     public interface IController10     {11         string Name { get; }12         IExecutor Executor { get; }13         IObserver Observer { get; }14     }15     public abstract class AbstractController : IController16     {17         protected string mName;18         protected IExecutor mExecutor;19         protected IObserver mObserver;20         //从外部传入被观察者21         //控制器内部构造观察者,并向被观察者注册,观察者和控制器总是成对出现22         protected AbstractController(string name, IExecutor executor)23         {24             this.mName = name;25             this.mExecutor = executor;26         }27 28         public virtual IExecutor Executor29         {30             get31             {32                 return this.mExecutor;33             }34         }35 36         public virtual string Name37         {38             get39             {40                 return this.mName;41             }42         }43 44         public virtual IObserver Observer45         {46             get47             {48                 return this.mObserver;49             }50         }51         //业务逻辑52         public virtual void HandExecuter()53         {54         }55         public virtual bool OnRemove(object o, params object[] assistant)56         {57             return this.mExecutor.OnRemove(o, assistant);58         }59         public virtual bool OnAdd(object o, params object[] assistant)60         {61             return this.mExecutor.OnAdd(o, assistant);62         }63         public virtual bool OnReplace(object o, params object[] assistant)64         {65             return this.mExecutor.OnReplace(o, assistant);66         }67 68     }69 }
View Code

被观察者

1 using System;  2 using System.Collections.Generic;  3 using System.Linq;  4 using System.Text;  5   6 namespace RGeos.FrameWork.MVC  7 {  8    //被观察者,执行者  9     public interface IExecutor 10     { 11         string Name { get; } 12  13         bool IsStateChanged { get; } 14  15         bool NeedRefresh { get; } 16         //观察者集合 17         List
Observers { get; } 18 19 bool OnAdd(object o, params object[] assistant); 20 bool OnRemove(object o, params object[] assistant); 21 bool OnReplace(object o, params object[] assistant); 22 23 void NotifyObservers(); 24 //添加观察者 25 bool RegisterObserver(IObserver view); 26 //注销观察者 27 bool UnRegisterObserver(IObserver view); 28 //注销所有观察者 29 bool UnRegisterObservers(); 30 } 31 public abstract class AbstractExecutor : IExecutor, ICloneable 32 { 33 protected bool mIsStateChanged; 34 protected string mName; 35 protected bool mNeedRefresh; 36 protected List
m_observers; 37 public bool IsStateChanged 38 { 39 get 40 { 41 return this.mIsStateChanged; 42 } 43 } 44 45 public string Name 46 { 47 get 48 { 49 return this.mName; 50 } 51 } 52 public bool NeedRefresh 53 { 54 get 55 { 56 return this.mNeedRefresh; 57 } 58 } 59 60 public List
Observers 61 { 62 get 63 { 64 return this.m_observers; 65 } 66 } 67 68 protected AbstractExecutor(string name) 69 { 70 this.mName = name; 71 this.mNeedRefresh = true; 72 this.mIsStateChanged = false; 73 this.m_observers = new List
(); 74 } 75 protected AbstractExecutor() 76 { 77 this.mNeedRefresh = true; 78 this.mIsStateChanged = false; 79 this.m_observers = new List
(); 80 } 81 82 83 public virtual object Clone() 84 { 85 return null; 86 } 87 88 public virtual bool RegisterObserver(IObserver observer) 89 { 90 if (this.m_observers == null) 91 { 92 this.m_observers = new List
(); 93 } 94 if (!this.m_observers.Contains(observer)) 95 { 96 this.m_observers.Add(observer); 97 return true; 98 } 99 return false;100 }101 102 public virtual bool UnRegisterObserver(IObserver observer)103 {104 if (this.m_observers != null)105 {106 while (this.m_observers.Contains(observer))107 {108 return this.m_observers.Remove(observer);109 }110 }111 return false;112 }113 114 public virtual bool UnRegisterObservers()115 {116 if (this.m_observers != null)117 {118 this.m_observers.Clear();119 this.m_observers = null;120 return true;121 }122 return false;123 }124 125 public virtual bool OnAdd(object o, params object[] assistant)126 {127 this.mIsStateChanged = true;128 this.NotifyObservers();129 return true;130 }131 public virtual bool OnRemove(object o, params object[] assistant)132 {133 this.mIsStateChanged = true;134 this.NotifyObservers();135 return true;136 }137 public virtual bool OnReplace(object o, params object[] assistant)138 {139 this.mIsStateChanged = true;140 this.NotifyObservers();141 return true;142 }143 public virtual void NotifyObservers()144 {145 if (this.mNeedRefresh)146 {147 if (this.mIsStateChanged)148 {149 foreach (IObserver observer in this.m_observers)150 {151 observer.OnUpdate(this);152 }153 }154 }155 this.mIsStateChanged = false;156 }157 }158 159 }
View Code

观察者

1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5  6 namespace RGeos.FrameWork.MVC 7 { 8     //观察者 9     public interface IObserver10     {11         IController Controller { get; }12         IExecutor Executor { get; }13         string Name { get; }14 15         void InitializeObserver();16         //更新观察者17         void OnUpdate(IExecutor currentExecutor);18     }19     public abstract class AbstractObserver : IObserver20     {21         protected IController mController;22         protected IExecutor mExecutor;23         protected string mName;24 25         public abstract void InitializeObserver();26         public abstract void OnUpdate(IExecutor currentExecutor);27 28         public virtual IController Controller29         {30             get31             {32                 return this.mController;33             }34         }35 36         public virtual IExecutor Executor37         {38             get39             {40                 return this.mExecutor;41             }42         }43 44         public virtual string Name45         {46             get47             {48                 return this.mName;49             }50         }51         //观察者通过控制器引用,调用被观察者的方法,更新其他的观察者。52         //此时观察者和被观察者不通信53         protected AbstractObserver(string name, IController controller)54         {55             this.mName = name;56             this.mController = controller;57             this.mExecutor = controller.Executor;58         }59         //在控制器中构造观察者时,将被观察者传入观察者,这样观察者可以调用被观察者中的数据。60         //此时观察者和被观察者通信61         protected AbstractObserver(string name, IController controller, IExecutor executor)62         {63             this.mName = name;64             this.mController = controller;65             this.mExecutor = executor;66         }67     }68 69 }
View Code

这个是MVC还是MVP?说不清。

 

转载地址:http://kvsia.baihongyu.com/

你可能感兴趣的文章
我的友情链接
查看>>
ElasticSearch 2 (32) - 信息聚合系列之范围限定
查看>>
VS2010远程调试C#程序
查看>>
windows查看端口占用
查看>>
Yii用ajax实现无刷新检索更新CListView数据
查看>>
App 卸载记录
查看>>
JavaScript变量和作用域
查看>>
开源SIP服务器加密软件NethidPro升级
查看>>
Apache Pulsar中的地域复制,第1篇:概念和功能
查看>>
python pip install 出现 OSError: [Errno 1] Operation not permitted
查看>>
南京大学周志华教授当选欧洲科学院外籍院士
查看>>
计算机网络与Internet应用
查看>>
oracle在线迁移同步数据,数据库报错
查看>>
linux性能剖析工具
查看>>
flutter中的异步
查看>>
计算机高手也不能编出俄罗斯方块——计算机达人成长之路(16)
查看>>
# 2017-2018-1 20155224 《信息安全系统设计基础》第七周学习总结
查看>>
scikit-learn预处理实例之一:使用FunctionTransformer选择列
查看>>
Cassandra监控 - OpsCenter手册
查看>>
《AngularJS深度剖析与最佳实践》简介
查看>>