返回目录 [ 最后更新:2021.3] 《编程导论(Java)·9.3.1回调》什么是好莱坞法则
1.3.1轮询VS. 通知 下层模块如何将进度数据传递给上层呢?轮询或通知
1.3.2 观察者模式 通知者在发生某种事件(如状态变化)时,通知所有已注册的观察者/监听器。
1.3.3 什么是好莱坞法则
好莱坞法则(the Hollywood Principle)原文:"Don't call me; I'll call you." (don't call us, we'll call you)。好莱坞法则并不深奥,GoF引用过的[ Swe85]的原文为:Don't call us, we'll call you (Hollywood's Law): A tool should arrange for Tajo to notify it when the user wishes to communicate some event to the tool, rather than adopt an 'ask the user for a command and execute it' model。其关键词为notify。
1. 本节的好莱坞法则
在通知机制中,上层模块女演员/Actress需要获得数据,她可以采用轮询方式获得数据,也可以应用通知方