官术网_书友最值得收藏!

Reactive programming

Most of us write imperative applications, where statements are required in order to change the application state. The code is executed and a final state is arrived at. After the state's computation, the state does not change when the underlying factors do. Let's consider the following code as an example:

int value1 = 5;
int value2 = 10;
int sum = val1 + val2;
System.out.println(sum); // 15
value1 = 15;
System.out.println(sum); // 15

The sum is still 15, even though value1 has been changed.

On the other hand, reactive programming is about the propagation of change. It is also referred to as declarative programming, where we express our intent and application state as dynamically determined by changes to underlying factors. The preceding sum program example, under a reactive paradigm, would behave as follows:

int value1 = 5;
int value2 = 10;
int sum = val1 + val2;
System.out.println(sum); // 15
value1 = 15;
System.out.println(sum); // 25

Consequently, if a program reacts to changes in the underlying factors, it can be called reactive. Reactive programs can be built using imperative techniques, like callbacks. This may be fine for a program that has a single event. However, for applications where hundreds of events are happening, this could easily lead to callback hell; we could have numerous callbacks relying on one another, and it would be really difficult to figure out which ones were being executed. As a result, we require a new set of abstractions that enable us to seamlessly build asynchronous, event-driven interactions across a network boundary. There are libraries in different imperative languages, like Java, that provide us with these abstractions. These libraries are referred to as Reactive Extensions. 

主站蜘蛛池模板: 成武县| 忻城县| 泸水县| 莆田市| 沁源县| 徐汇区| 万宁市| 上思县| 策勒县| 家居| 漾濞| 定边县| 新竹县| 汾阳市| 宜黄县| 罗江县| 永吉县| 义乌市| 灵宝市| 红桥区| 饶平县| 黔江区| 中牟县| 长岭县| 河间市| 凤翔县| 老河口市| 吴旗县| 巴楚县| 永靖县| 棋牌| 织金县| 衡水市| 黄冈市| 玛纳斯县| 泉州市| 宜君县| 军事| 双桥区| 秦皇岛市| 隆安县|