- Hands-On Reactive Programming with Reactor
- Rahul Sharma
- 233字
- 2021-08-13 15:22:55
The Observable interface
The java.util.Observable interface implements the Observer pattern, which can be co-related here. However, all similarities end here. If we look at the Observable interface, we have the following methods:
public class Observable {
void addObserver (Observer o);
void deleteObserver (Observer o);
void deleteObservers();
void notifyObservers();
void notifyObserver(int arg);
int countObservers();
boolean hasChanged();
}
Let's look at the Observer interface before we determine the differences:
public interface Observer{
void update(Observable o, Object arg)
}
If we look at the Observable and Observer interfaces, we can see that they are all about a single event and its state. The Observable API has the responsibility of determining a change and publishing it to all interested parties. On the other hand, the Observer only listens to the change. This is not what we are modeling with the Publisher and Subscriber interface. The Publisher interface is responsible for generating unbounded events, unlike the Observable, which is all about single entity state changes. The Subscriber, on the other hand, lists all kinds of events, such as data, error, and completion.
Furthermore, the Observable maintains an active list of observers. It has the responsibility of removing observers that are no longer interested in the event. This is not the same as the Publisher, which is only responsible for subscriptions. The Subscriber makes the decision to close the subscription, at its will.
- Introduction to DevOps with Kubernetes
- Getting Started with MariaDB
- CSS全程指南
- 返璞歸真:UNIX技術(shù)內(nèi)幕
- 自動(dòng)化生產(chǎn)線(xiàn)安裝與調(diào)試(三菱FX系列)(第二版)
- 網(wǎng)絡(luò)服務(wù)器搭建與管理
- Natural Language Processing and Computational Linguistics
- 手把手教你學(xué)Photoshop CS3
- Eclipse RCP應(yīng)用系統(tǒng)開(kāi)發(fā)方法與實(shí)戰(zhàn)
- Java求職寶典
- Cisco UCS Cookbook
- 傳感器應(yīng)用技術(shù)
- 微計(jì)算機(jī)原理及應(yīng)用
- Apache Hadoop 3 Quick Start Guide
- 我的IT世界