Difference between Imperative Approach and Reactive Approach



Imperative Approach

  1. 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.
  2. 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
  3. Order of execution is Important - Synchronous
  4. 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
  1. 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.
  2. 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
  3. Order of execution Not important - Asynchronous
  4. Provides flexible and scalable to architecture e.g. MVVM

Eg:
int val1 = 10;
int val2 = 20;
int sum = val1 + val2;
System.out.println(sum); // 30
val1 = 5;
System.out.println(sum); // 25

Comments

Popular posts from this blog

Android Interview question

A complete guide to learn Android Development