观察者模式
来源:互联网 发布:昆明java 编辑:程序博客网 时间:2024/06/03 20:22
using System.Collections.Generic;
using System.Collections;
using UnityEngine;
public abstract class Subject01
{
private List<Observer01> ob = new List<Observer01>();
public void Attach(Observer01 obser)
{
ob.Add(obser);
}
public void RemoveObj(Observer01 obser)
{
ob.Remove(obser);
}
public void Notify()
{
foreach (Observer01 o in ob)
{
o.Receive();
}
}
}
using System;
using System.Collections.Generic;
using System.Collections;
using UnityEngine;
public class MySubject:Subject01
{
private string subjectState;
public string SubjectState
{
get { return subjectState; }
set { subjectState = value; }
}
}
using System;
using System.Collections.Generic;
using System.Collections;
public abstract class Observer01
{
public abstract void Receive();
}
using System;
using System.Collections.Generic;
using System.Collections;
using UnityEngine;
public class MyObserver : Observer01
{
private string name;
public MyObserver(string name)
{
this.name = name;
}
public override void Receive()
{
Debug.Log(name);
}
}
using UnityEngine;
using System.Collections;
public class MyText : MonoBehaviour {
// Use this for initialization
void Start () {
MySubject sub = new MySubject();
sub.Attach(new MyObserver("111"));
sub.Attach(new MyObserver("222"));
sub.Notify();
}
// Update is called once per frame
void Update () {
}
}
- 观察者模式
- 观察者模式
- 观察者模式
- 观察者模式
- 观察者模式
- 观察者模式
- 观察者模式
- 观察者模式
- 观察者模式
- 观察者模式
- 观察者模式
- 观察者模式
- 观察者模式
- 观察者模式
- 观察者模式
- 观察者模式
- 观察者模式
- 观察者模式
- Idea 的@Autowired标红报错
- shell脚本 编写
- tomcat7放入war不解析
- Java异常类层次结构图
- SpringBoot从入门到高级
- 观察者模式
- Qt QWizard学习 当需要验证输入时
- Flask04 后台获取请求数据、视图函数返回类型、前台接受响应数据
- 【Web前端学习笔记】Javascript_01_变量,数据类型,类型转换
- 比特币:一个P2P电子现金系统
- Spring-AOP @AspectJ进阶之访问连接点信息
- JavaScript的定时器运用以及鼠标事件的运用
- centos7.0 安装多个5.7 mysql
- C语言问题集锦1-10