Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (1)
master
master
Branches (1)
master
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (1)
master
Main.java 1.35 KB
Copy Edit Raw Blame History
彭冠铭 authored 2018年04月16日 22:36 +08:00 . first commit
package Observer.jdk;
import Observer.ConcreateSubject;
/**
* @author ngfngf
*java实现与自己实现的对比
* 1不需要再定义观察者和目标接口了,JDK帮忙定义
* 2具体目标实现里面不需要再维护观察者的注册信息了
*JDK咋在Observable已经帮忙实现好了
* 3触发通知的方式有一点变化,要先调用setChanged(),这个是
*JDK为了帮助实现更精确的触发控制而提供的功能
* 4具体观察者的实现里面,update()其实能同时支持推模型和拉模型
*这是JDK在定义的时候就已经考虑进去了
*
*优
* 1观察者和目标之间的抽象耦合
* 2动态联动
* 3支持广播通信
*
*缺
* 1可能引起误操作
*
*本质:触发联动
*
*场景:1当一个抽象模型有两个方面,其中一个方面的操作依赖于另一个方面的状态变化
* 2如果在更改一个对象的时候,需要同时连带改变其他的对象,而不知道究竟有多少个对象需要被连带改变
* 当一个对象必须通知其他的对象,但是你又希望这个对象和其他被通知的对象是松散耦合的
*
*/
public class Main {
public static void main(String[] args) {
//创建目标对象
ConcreateWeatherSubject subject = new ConcreateWeatherSubject();
//创建观察者
ConcreateObserver observerGirl = new ConcreateObserver();
observerGirl.setObserverName("范冰冰");
ConcreateObserver observerMuml = new ConcreateObserver();
observerMuml.setObserverName("我的老妈");
//注册观察者
subject.addObserver(observerMuml);
subject.addObserver(observerGirl);
//目标更新天气情况
subject.setContent("明天天气晴朗,蓝天白云");
}
}
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

Cancel

Releases

No release

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/pgm250/JavaSe.git
git@gitee.com:pgm250/JavaSe.git
pgm250
JavaSe
JavaSe
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /