Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥

Clean Android Architecture

Richa
April 10, 2015

Clean Android Architecture

Diving into problems with MVC and refactoring it into Clean Architecture - VIPER + MVVM, and talking about pros and cons of this architecture.

Richa

April 10, 2015
Tweet

More Decks by Richa

Other Decks in Programming

Transcript

  1. MODEL VIEW CONTROLLER Interact with DB Render Model Handle view

    events Interact with API/cloud code Manage view state Update model Invoke another view Interact with system components Handle system events Update view based on system events
  2. View public class ExpandableCourseListActivity { public void onPause() { //

    save all expanded states } public void onResume() { // restore all expanded states } }
  3. Controller public void onClick() {} public void onModelUpdated() {} public

    void onNewNotification() {} public void onLocationUpdated(Location location) {} public void takePhoto(Activity activityContext) {} public void launchProfilePage(Activity activityContext ) {}
  4. MODEL VIEW CONTROLLER Interact with DB Render Model Handle view

    events Interact with API/cloud code Manage view state Update model Invoke another view Interact with system components Handle system events Update view based on system events
  5. MODEL VIEW CONTROLLER INTERACTOR Retrieve data from Network Render Model

    Handle view events Interact with external entities Retrieve data from API/cloud code Manage view state Invoke another view Forward system events to view Forward model updates to view
  6. MODEL VIEW CONTROLLER INTERACTOR VIEW MODEL Retrieve data from Network

    Render View Model Handle view events Interact with external entities Encapsulate view state and behavior Retrieve data from API/ cloud code Invoke another view Update view state
  7. MODEL VIEW PRESENTER INTERACTOR VIEW MODEL Retrieve data from Network

    Render View Model Handle view events Interact with external entities Encapsulate view state and behavior Retrieve data from API/ cloud code Invoke another view Update view state
  8. ENTITIES VIEW PRESENTER INTERACTOR VIEW MODEL Retrieve data from Data

    Sources Render View Model Handle view events Interact with external entities Encapsulate view state and behavior Invoke another view Update view state
  9. ENTITIES VIEW PRESENTER INTERACTOR VIEW MODEL ROUTER Retrieve data from

    Data Sources Render View Model Handle view events Interact with external entities Encapsulate view state and behavior Invoke another view Update view state
  10. CatalogPresenter public void loadCatalog() { interactor.loadInteractor() .subscribe(new Action1<List<Course>>() { @Override

    public void call(List<Course> courses) { getData().mCourseList.onNext(courses); } }); }
  11. CatalogViewModel public final BehaviorSubject<Catalog> catalog = BehaviorSubject.create(); public void subscribeToCatalog(Action1

    action) { catalog.subscribe(action); } public void unsubscribeToCatalog() { catalog.unsubscribe(action); }
  12. CatalogInteractor Context mContext; public CatalogInteractor(Context context) { mContext = context;

    } public Observable loadCatalog() { return catalogDataSource.loadCatalog(); }
  13. Build features in new architecture rather than refactor Validate Iterate

    - learn and apply Don’t refactor all the time