- Building RESTful Web Services with Spring 5(Second Edition)
- Raja CSP Raman Ludovic Dewailly
- 343字
- 2021-06-30 19:13:24
Imperative and Reactive programming
Let's see a small comparison between Imperative programming and Reactive programming: x = y + z.
In the preceding expression, assume y = 10 and z = 15. In this case, the x value would be 25. The value of x would be assigned at the time of the expression x = y + z. The value of x will never change after this expression.
This is perfectly alright in the traditional programming world. However, we might need a scenario where we should be able to follow up x when we change the value of y or z.
Our new scenario based values are:
- When y = 20 and z = 15, then x = 35
- When y = 20 and z = 25, then x = 45
The preceding scenario is not possible in Imperative programming, which we regularly use in our daily programming. But in some cases, we might need the value of x to be updated, corresponding to the change in y or z. Reactive programming is the perfect solution for this scenario. In Reactive programming, the value of x would automatically be updated, corresponding to the change in y or z.
Spreadsheet reference cells are the best example of Reactive programming. If a cell value changes, the referred cell value will be updated automatically. Another example can be found in a Model-View-Controller architecture, Reactive programming can automatically update the View, which is attached to the Model.
Reactive programming follows the Observer pattern to manipulate and transform the stream of data where the Publisher (observable) emits the items based on the Subscriber's need. As the Publisher emits the item, the Subscriber consumes those emitted items from the Publisher. Unlike the iterator pulling the items, here, the Publisher is pushing the items to the Subscriber.
As Reactive is a part of non-blocking architecture, it will be useful when we scale the application. Also, in non-blocking architecture, everything is considered as an event stream.
We will discuss more about Reactive in Java and Spring later in this chapter.
- 社交網絡對齊
- 網絡創新指數研究
- SD-WAN架構與技術(第2版)
- Spring Cloud微服務架構進階
- 互聯網安全的40個智慧洞見:2014年中國互聯網安全大會文集
- Yii Application Development Cookbook(Second Edition)
- Metasploit Penetration Testing Cookbook
- 人人都該都懂的互聯網思維
- AIoT應用開發與實踐
- 深入理解Nginx:模塊開發與架構解析
- 5G技術核心與增強:從R15到R17
- 華為HCIA-Datacom認證指南
- 精通SEO:100%網站流量提升密碼
- Guide to NoSQL with Azure Cosmos DB
- 工業以太網技術:AFDX/TTE網絡原理、接口、互連與安全