C#观察者模式
来源:互联网 发布:战舰世界 个人数据 编辑:程序博客网 时间:2024/05/23 00:31
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Blog : MonoBehaviour{
public class ModalBase{
public delegate void EventHanler();
public event EventHanler Event;
public void UpdateData(){
this.Event ();
}
}
public class Observer{
public Observer(ModalBase modal){
modal.Event+=new ModalBase.EventHanler(Response);
}
public virtual void Response(){
}
}
public class Cat:ModalBase{
public void Shout(){
Debug.Log ("猫大叫");
this.UpdateData ();
}
}
public class Mouse:Observer{
public Mouse(ModalBase modal):base(modal){
}
public override void Response ()
{
base.Response ();
Debug.Log ("老鼠跑路");
}
}
public class Man:Observer{
public Man(ModalBase modal):base(modal){
}
public override void Response ()
{
base.Response ();
Debug.Log ("人醒来");
}
}
void Start(){
Cat cat = new Cat ();
Mouse mouse = new Mouse (cat);
Man man = new Man (cat);
cat.Shout ();
}
}
using System.Collections.Generic;
using UnityEngine;
public class Blog : MonoBehaviour{
public class ModalBase{
public delegate void EventHanler();
public event EventHanler Event;
public void UpdateData(){
this.Event ();
}
}
public class Observer{
public Observer(ModalBase modal){
modal.Event+=new ModalBase.EventHanler(Response);
}
public virtual void Response(){
}
}
public class Cat:ModalBase{
public void Shout(){
Debug.Log ("猫大叫");
this.UpdateData ();
}
}
public class Mouse:Observer{
public Mouse(ModalBase modal):base(modal){
}
public override void Response ()
{
base.Response ();
Debug.Log ("老鼠跑路");
}
}
public class Man:Observer{
public Man(ModalBase modal):base(modal){
}
public override void Response ()
{
base.Response ();
Debug.Log ("人醒来");
}
}
void Start(){
Cat cat = new Cat ();
Mouse mouse = new Mouse (cat);
Man man = new Man (cat);
cat.Shout ();
}
}
阅读全文
0 0
- C# 之观察者模式
- C#中的观察者模式
- c#观察者模式
- c# 观察者模式
- C#设计模式观察者
- C# 观察者模式.
- c#观察者模式
- c#之观察者模式
- C# 观察者设计模式
- C#观察者模式设计
- C#观察者模式
- C#观察者模式
- c# 设计模式:观察者模式
- c#设计模式-观察者模式
- c# 设计模式:观察者模式
- c#设计模式-观察者模式
- 【C#设计模式-观察者模式】
- c#设计模式-观察者模式
- Java 流(Stream)、文件(File)和IO
- WOJ1016-cherry Blossom
- P3088突击小组
- JVM类加载机制
- fastjson 字段转换不区分大小写
- C#观察者模式
- 神奇6位数--蓝桥杯国赛j历年真题
- Ubuntu16.04安装redis和php的redis扩展
- 深入分析Docker镜像原理
- 斐波那契数列java实现
- 泛型与Class类
- Cyclic Nacklace
- 改坏了/etc/profile后的解决方法
- [笔记分享] [Display] LCD接口介绍