Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
OneCodeOneTime
DesignPatternsJava
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
DesignPatternsJava
/
src
/
Observer
/
ConcreteSubject.java
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
25 lines (23 loc) · 1.28 KB
master
Breadcrumbs
DesignPatternsJava
/
src
/
Observer
/
ConcreteSubject.java
Copy path
Top
File metadata and controls
Code
Blame
25 lines (23 loc) · 1.28 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package
Observer
;
import
java
.
util
.
Observable
;
import
java
.
util
.
Observer
;
/**
* @Component:具体的主题:被观察者,被观察者改变了要通知在它上面注册的观察者,继承自java.util.Observable
* java已经提供了对观察者模式的支持:java.util.Observable(被观察者)以及java.util.Observer(观察者)
* 观察者观察的对象,在内会维护一个观察者的列表,订阅会添加观察者,取关会删除观察者。当发生变化,会通知并更新订阅的观察者。
* @author btp
*
*/
public
class
ConcreteSubject
extends
Observable
{
//Observable维护一个线程同步的Vector
//public synchronized void addObserver(Observer o) -> 注册一个观察者对象
//public synchronized void deleteObserver(Observer o) -> 取消一个观察者对象的订阅
//public void notifyObservers() -> 通知更新观察者
//public void notifyObservers(Object arg) -> 通知更新观察者
//public synchronized void deleteObservers() -> 清空所有的观察者
//protected synchronized void setChanged() -> 设置被观察者为修改状态,此时可通知并更新观察者们
//protected synchronized void clearChanged() -> 设置被观察者为无修改状态,一般通知并更新完观察们之后调用
//public synchronized boolean hasChanged() -> 返回此时被观察者是否有更新
//public synchronized int countObservers() -> 返回此时在被观察者上注册的观察者的数量
//and so on...add the information the ConcreteSubject contained
}
You can’t perform that action at this time.