Difference between Imperative Approach and Reactive Approach
Imperative Approach
- Pull based approach , means as a developer I am responsible for everything. Like I want to know any change in data I want to ask.
- Redundant code .Take data in Callback and later they share by using EventBuses, Broadcast Receivers or save in static objects. Or Polling mechanism ,so What I am doing now. This method call after every 1s or 1000ms
- Order of execution is Important - Synchronous
- Difficulty in scalability . eg. MVC
Eg:
int val1 = 10;
int val2 = 20;
int sum = val1 + val2;
System.out.println(sum); // 30
val1 = 5; System.out.println(sum); // 30
Reactive Approach
- In Push approach developer only write simple code and give orders to data. Hey if any change in you, inform me. Achieved using observer pattern.
- Removes boilerplate code. If you want data from API’s which will be shared with more then one screens or classes on same time, always use Observer Pattern . Observer Pattern which is a base of Rx
- Order of execution Not important - Asynchronous
- Provides flexible and scalable to architecture e.g. MVVM
int val1 = 10;
int val2 = 20;
int sum = val1 + val2;
System.out.println(sum); // 30
val1 = 5;
System.out.println(sum); // 25
Comments
Post a Comment