惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cisco Talos Blog
Cisco Talos Blog
阮一峰的网络日志
阮一峰的网络日志
云风的 BLOG
云风的 BLOG
D
Docker
Vercel News
Vercel News
IT之家
IT之家
Recent Announcements
Recent Announcements
Last Week in AI
Last Week in AI
V
Visual Studio Blog
Engineering at Meta
Engineering at Meta
腾讯CDC
Google DeepMind News
Google DeepMind News
I
InfoQ
博客园 - 三生石上(FineUI控件)
Apple Machine Learning Research
Apple Machine Learning Research
The GitHub Blog
The GitHub Blog
博客园 - Franky
The Cloudflare Blog
A
About on SuperTechFans
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
T
Tenable Blog
P
Proofpoint News Feed
Recorded Future
Recorded Future
Security Latest
Security Latest
H
Hackread – Cybersecurity News, Data Breaches, AI and More
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 聂微东
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Google Online Security Blog
Google Online Security Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Simon Willison's Weblog
Simon Willison's Weblog
The Last Watchdog
The Last Watchdog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
N
News and Events Feed by Topic
TaoSecurity Blog
TaoSecurity Blog
U
Unit 42
The Hacker News
The Hacker News
Martin Fowler
Martin Fowler
T
Threat Research - Cisco Blogs
NISL@THU
NISL@THU
F
Full Disclosure
M
MIT News - Artificial intelligence
人人都是产品经理
人人都是产品经理
Hugging Face - Blog
Hugging Face - Blog
V
V2EX
Project Zero
Project Zero

博客园 - 程序猿101

2024年总结。。。。2025年规划。 八皇后问题c语言版(xcode下通过) 对分布式一些理解 用redis实现悲观锁(后端语言以php为例) 只用200行Go代码写一个自己的区块链!(转) 用户中心 - 博客园 php的生命周期的概述 linux网络编程1 最简单的socket编程 mysql 慢查询 2016年终总结。。。六年从创业到技术的历程 Linux下chkconfig命令详解 这个简单明了啊 JS的prototype和__proto__ Constructor vagrant homestead laravel 编程环境搭建 发现一个百度的密码。。。记最近一段时间的php感想 mysql 的简单优化 百度面试题 字符串相似度 算法 similar_text 和页面相似度算法 百度的面试题 合并两个有序的数组 PHP性能优化工具–xhprof安装 Ecshop :后台添加新功能 菜单及 管理权限 配置
观察者模式
程序猿101 · 2018-04-13 · via 博客园 - 程序猿101
//观察者模式

/**
 *
 * 大概意思就是,当一个事件的状态发生改变之后,通知其他依赖的事务。
 *
 * 一般的做法是代码下面直接撸代码, 这样的不好的地方就是,没增加一个依赖都需要对下面增加,接着更改。
 * 逻辑多了,就会很长很长。当然大部分会每个依赖业务封装到一个方法中。如果模块太大可能就拆分做队列了。
 * 其他依赖直接消费队列就可以了。
 * 现在有一种模式可以解决这种方法。
 * 大概就是下面代码的样子。
 * Class upload
 */

class upload{
    public $_obervers = [];
    /**
     * 增加订阅对象
     * @param $object
     */
    public function register($object){
        $this->_obervers[] = $object;
    }

    /**
     * 触发器
     */
    public function trigger(){
        if(empty($this->_obervers)){
            return;
        }
        foreach($this->_obervers as $obj){
            $obj->execute();
        }
    }

    /**
     * 具体操作事务
     */
    public function htm5toxml(){
        echo 'upload is end';
        echo "\r\n";
        $this->trigger();
    }
}

class a{
    public function execute(){
        echo 'this is a execute';
        echo "\r\n";
    }
}

class b{
    public function execute(){
        echo 'this is b execute';
        echo "\r\n";
    }
}

$upload = new upload();

$upload->register(new a());
$upload->register(new b());

$upload->htm5toxml();