Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Android Clean Architecture for Dummies

4,612 views

Published on

Brief tutorial of implementing very primitive app(single list view) using Android Clean Architecture. It won't describe what and why, but rather, how to use it.

Published in: Engineering

Android Clean Architecture for Dummies

  1. 1. 2015/11/17 @kengoScal Android Clean Architecture for Dummies
  2. 2. About Me 2
  3. 3. Self Introduction name: Kengo Suzuki twitter: @kengoScal 3 2011∼2014:Security Analyst 2014年11月: Joined MoneyForward 2014年11月∼2015年01月: iOS 2015年02月∼08月:Android 2015年09月∼10月 : Security Architect 2015年11月 : Security Architect/Management + Android
  4. 4. 4 In Charge of New Android App!
  5. 5. Android Clean Architecture 5
  6. 6. What is it & Why using it? 6
  7. 7. What is it & Why using it? 7 Not Today.
  8. 8. Plenty of Good Entries(with source codes) 8 • English • Architecting Android…The Clean Way? • Clean Android Architecture • MVP for Android: how to organize presentation layer • Japanese • AndroidオールスターズでClean Architectureについて発 表してきた • これからの設計の話をしよう • AndroidではMVCよりMVPの方がいいかもしれない
  9. 9. Plenty of Good Entries(with source codes) 9 • English • Architecting Android…The Clean Way? • Clean Android Architecture • MVP for Android: how to organize presentation layer • Japanese • AndroidオールスターズでClean Architectureについ て発表してきた • これからの設計の話をしよう • AndroidではMVCよりMVPの方がいいかもしれない Big Picture Source Code Roles Big Picture Roles Presenter
  10. 10. Right off the Bat? 10 訳: すぐに/直ちに
  11. 11. Need Endurance! 11 • Codes aren t self explanatory • Lack of experience in using core liibraries could be pain • Don t know what goes where.
  12. 12. 12
  13. 13. Architecure is About Intent, not Frameworks 13 by Robert Cecil Martin
  14. 14. With the Hope, no one gives up architecting 14
  15. 15. How to use it (Tutorial) 15
  16. 16. Primitive App 16 • Single Activity • Single List View • Horizontally aligned texts • Fab • click and fetch data • Fetch MusicList(data) • by Retrofit • freemusicarchive.org • DI and EventHub • Under Construction
  17. 17. Click And Fetch Data Tutorial 17
  18. 18. The Goal 18 • Click Fab • Run Retrofit to fetch data • Not considering data response
  19. 19. 19 What We Will Implement • reference • Architecting Android…The Clean Way?: • これからの設計の話をしよう
  20. 20. Thing You Need To Implement 20 • MainActivity • MusicListPresenter • MusicListUseCase • MusicListUseCaseImpl • MusicListRepository • MusicListRepositoryImpl • MusicListEntity
  21. 21. Data Domain Presentation Thing You Need To Implement 21 • MainActivity • MusicListAdapter • MusicListPresenter • MusicListUseCase • MusicListUseCaseImpl • MusicListRepository • MusicListRepositoryImpl • MusicListEntity
  22. 22. Presentation - UserAction 22 • Main Activity & MusicListAdapter • Render List View attaching adapter • Initialize followings • repository, usecase, presenter • Pass FAB clicked event along with Main Thread Info to Presenter • MusicListPresenter • Receive FAB clicked event from View • Execute MusicListUseCase(Imp) Job • Pass thread info to MusicListUseCas(Imp)
  23. 23. 23 What We Just Implemented • reference • Architecting Android…The Clean Way?: • これからの設計の話をしよう
  24. 24. Domain - User Action to Data Interface 24 • MusicUseCase • Provide interface between Domain Layer & Presentation Layer • MusicUseCaseImp • Ask MusicListRepository(Imp) for API(External Resource) • MusicListRepository • Provide interface between Domain Layer & Data Layer
  25. 25. 25 What We Just Implemented • reference • Architecting Android…The Clean Way?: • これからの設計の話をしよう
  26. 26. Data - Data Interface to DataSource 26 • MusicListRepositoryImp • To Fetch external Data • Declare and Execute Retrofit Http Client • GET http://freemusicarchive.org/api? key={key} • MusicListEntity • Parse Response and map to domain/model • gson will handle it.
  27. 27. 27 What We Just Implemented • reference • Architecting Android…The Clean Way?: • これからの設計の話をしよう
  28. 28. That s it for Fetching Data 28 Now we want to Reflect Data
  29. 29. Reflect Data to View Tutorial 29
  30. 30. The Goal 30 • Pass back data just fetched • Update View
  31. 31. 31 What We Will Implement • reference • Architecting Android…The Clean Way?: • これからの設計の話をしよう
  32. 32. Thing You Need To Implement 32 • MusicListRepository#MusicListFetchCallback • MusicListUseCaseImpl • MusicListUseCase#MusicListUseCaseCallback • MusicListPresenter • MusicListPresenter#MusicListViewCallback • MainActivity
  33. 33. Presentation Domain Data Thing You Need To Implement 33 • MusicListRepository#MusicListFetchCallback • MusicListUseCaseImpl • MusicListUseCase#MusicListUseCaseCallback • MusicListPresenter • MusicListPresenter#MusicListViewCallback • MainActivity
  34. 34. Domain - Passing Data to User Interface 34 • MusicListRepository#MusicListFetchCallback • MusicListUseCaseImpl • Implement MusicListFetchCallback • So that Main Threat can receive runnable with command with fetched data • MusicListUseCase#MusicListUseCaseCallback • MusicListPresenter • MusicListPresenter#MusicListViewCallback • MainActivity
  35. 35. 35 What We Just Implemented • reference • Architecting Android…The Clean Way?: • これからの設計の話をしよう
  36. 36. Presentation - Updating View 36 • MusicListUseCase#MusicListUseCaseCallback • MusicListPresenter#MusicListViewCallback • MusicListPresenter • Implement MusicListUseCaseCallback • Execute methods in MusicListViewCallback • MainActivity • Implement MusicListViewCallback • So that User Case can pass fetched data • So that Activity can update adapter data
  37. 37. 37 What We Just Implemented • reference • Architecting Android…The Clean Way?: • これからの設計の話をしよう
  38. 38. That s it! 38
  39. 39. Lots of Room for Improvement 39 • Callback Repetition is quite Ugly • Many Reinvent Wheel • Not using Dagger, RxJava • Not a big fun of passing thread around • Tutorial itself wasn t thoroughly covered
  40. 40. Still, Worthwhile 40 Especially, in the team
  41. 41. Enjoy Clean Architecting! 41
  42. 42. Thank you!
  43. 43. References 43 • English • Architecting Android…The Clean Way?: http://fernandocejas.com/ 2014/09/03/architecting-android-the-clean-way/ • Clean Android Architecture: https://speakerdeck.com/richk/clean- android-architecture • MVP for Android: how to organize presentation layer: http:// antonioleiva.com/mvp-android/ • Japanese • AndroidオールスターズでClean Architectureについて発表してきた: http:// tomoima525.hatenablog.com/entry/2015/08/13/190731 • これからの設計の話をしよう: http://www.slideshare.net/ shinnosukekugimiya/ss-50705888 • AndroidではMVCよりMVPの方がいいかもしれない: http:// konifar.hatenablog.com/entry/2015/04/17/010606

×