Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Android Architecture 총정리

Android Architecture 총정리

당신의 아키텍처, 뭔가 잘못된 것 같은 느낌에 시달리고 있지는 않나요? MVP부터 MVVM, Flux 그리고 클린 아키텍처까지 Best Practice를 중심으로 현업에서 어떤 아키텍처를 적용할 것인가에 대해, 그리고 아키텍처 관점에서 의존성 주입, Rx, 코루틴, 멀티모듈 등의 기술을 어떻게 적용할 수 있을지, 2018년에 이어 더욱 깊은 내용으로 다뤄봅니다.

동영상 링크: https://www.youtube.com/watch?v=0LL7FCWTxoo

Sa-ryong Kang

April 05, 2019
Tweet

More Decks by Sa-ryong Kang

Other Decks in Programming

Transcript

  1. Who is this guy? • ҃۱ 19֙ର SW ূ૑פয •

    ತস ੹ޙо: ޷Ҵীࢲ ೠ ߣ, ೠҴীࢲ ف ߣ झఋ౟স ହস ҃೷ • IBM iX Japanীࢲ Android/iOS ׸׼ Senior Specialist۽ Ӕޖ ઺ • Droid Knights 2018 - ղо উ٘۽੉٘ ূ૑פযо غ঻ਸ ٸ ইޖب ঌ۰઱ ૑ ঋ਷ Ѫٜ
  2. IBM iX Japan - We’re building business by design •

    Design Thinking, Mobile Interaction, Digital Strategy, … • ઝ਋૑р ࢜܂Ҋ ੤߀Ҋ, ਬ੷ ૑ೱ੸ੋ न ӝࣿ/ࢎসਸ ҳഅ೧઱ח ஶࢸ౴ ઑ૒ • ઱ਃ Ҋё: ੌࠄ 10؀ Ӓܛ, ਷೯ࢎ, ন؀ ೦ҕࢎ
  3. ݾର • Part I. ࢲۿ 1. ઱੄ࢎ೦ 2. ࢶࣻ ૑ध:

    উ٘۽੉٘ ইఃఫ୊ 4࠙݅ী ߶ۅ஖ӝ - MVC, Clean Architecture, Testability, Reusability • Part II. Non-MVC ইఃఫ୊ ୨੿ܻ 1. Non-MVC ইఃఫ୊੄ ӝࠄ ࢸ҅ ੹ۚ 2. MVP 3. MVVM 4. Redux • Part III. New Trend in 2019 1. Rx vs non-Rx 2. Multi-module • Part IV. Best Practices
  4. 1. द੘ೞӝ ੹ ઱੄ࢎ೦ • ૑ա஘ ӝ؀ Ә૑ - 45࠙

    ъ੄ী ցޖ ݆਷ Ѧ ӝ؀ೞदݶ ݒ਋ Ҍۆ.. • ঐӝ Ә૑ - ਗܻܳ ੉೧ೞח Ѫ੉ ؊ ઺ਃ • ޖడ؀Ҋ ժٙೞӝ Ә૑ - ৵ ੷۠ ফӝܳ ೞחоܳ ੉೧ೞҊ, ౸ױ਷ ৈ۞࠙ झ झ۽ • ࢎ૓ ୫৔ ޖॶݽ: ठۄ੉٘ח ইې ݂௼ীࢲ ׮਍ ߉ਵप ࣻ ੓णפ׮ • https://speakerdeck.com/saryong
  5. ৵, ౠ߹൤ উ٘۽੉٘ ইఃఫ୊ ࢸ҅/ҳഅী ੓যࢲ, ࠺౸੸ ࢎҊ о ઺ਃೠо?

    • General Practiceח ݆਷ؘ Best Practiceח ଺ইࠁӝ য۵׮ • ब૑য Gࢎо ݅ٚ ࢠ೒ઑର цۿਸ߅੄ ৈ૑о.. • ইఃఫ୊ ಁఢ੄ Ѯਸ ݍࠁѱ ೧઱ח Ӗ਷ ݆૑݅ ೨ब ୍೟ী ؀೧ ফӝೞ ח Ӗ਷ ݒ਋ ൞߅ೞ׮ • э਷ ੉ܴਸ о૓ ইఃఫ୊ ಁఢب п੗ ࢚ടী ٮۄ ݒ਋ ੉૕੸ਵ۽ ҳഅؼ ࣻ ੓׮
  6. 2. ࢶࣻ૑ध • Architecture੄ ӝࠄ ઺੄ ӝࠄ: MVCۆ ޖ঺ੋо? •

    Model = State + ࠺ૉפझ ۽૒ + ؘ੉ఠ ੷੢ࣗ • View = UI (ࠁా declarativeೞѱ ҳഅؽ) • Controller = Flow ۽૒ + [࠺ૉפझ ۽૒] + [State]
  7. (30ୡ݅ী ੉೧ೞח) Clean Architecture੄ ӝࠄ • MVCীࢲ Modelਸ ࠙೧ →

    Domain Layer + Data Layer • MVCীࢲ ࠺ૉפझ ۽૒ਸ ࠙೧ → Presentational Logic (in Presenter) / Domain Logic (in UseCase) ୹୊: https://qiita.com/koutalou/items/07a4f9cf51a2d13e4cdc
  8. • Ӓؘ۠, ই઱ ੘਷ ࠗ࠙୊ۢ ࠁ੉ח Presentation Logicী ઱۽ ઱ݾೞח

    ੉ਬח? • بݫੋ ۽૒੉ ର૑ೞח ࠗ࠙੉ (࢚؀੸ਵ۽) ੸਺ - ؀ࠗ࠙੄ জ੄ ҃਋, о੢ ࠂ ੟ೠ ࠺ૉפझ ۽૒਷ ߔূ٘ ࢲߡী ઓ੤ೣ • ࠂ੟ೞҊ (؀ࠗ࠙) ࠺زӝ੸ੋ ࢚క੄ ҙܻ, ӒܻҊ ۄ੉೐ ࢎ੉௿ োز੉ ഻ঁ ࠂ ੟ೞҊ ઺ਃೠ ޙઁ • ߄Լ ফӝೞݶ ݽ߄ੌ ইఃఫ୊ীࢲ о੢ ௾ դઁח tight coupling between ui and state changes ܳ যڌѱ ೧ࣗೡ Ѫੋо੄ ޙઁ
  9. ইఃఫ୊ ҙ੼ীࢲ ইې ف ѐ֛਷ ৵ Ӓܻ ઺ਃೠо? • పझ౟

    оמࢿ • ੤ࢎਊࢿ
 
 • “դ ਬ׫పझ౟ ٮਦ ೙ਃ হয!”ۄҊ ର݃ ݈ೞӝ ੹ী.. • Testablilityо ڄয૑ח ௏٘ۆ ޖ঺ੋо ࢤп೧ ࠇद׮ → Tightly-coupled • పझ౟ оמࢿ੉ ڄয૑ח ௏٘ח ઺ਃ ۄ੉࠳۞ܻ ߸҃, ӝ߈ ҳઑ ߸҃ী ؀਽ೞӝо য۵׮ • “അप੸ਵ۽ ೠ ߣ ૠ ௏٘ܳ ௿ېझ/Fragment ױਤ۽ ੤ࢎਊ оמೠ ҃਋о ঴݃ա ظ?”ۄҊ ର݃ ݈ೞӝ ੹ী.. • Re-usabilityۆ ѱ গୡী ޖ঺੉঻ա ࢤп೧ࠇद׮ → ੸੺ೠ ݽٕച, ஭ङച • ੤ࢎਊࢿ੉ ڄয૑ח ҳઑח ӝמ ߸҃ / ഛ੢ࢿ੉ ڄয૓׮ ≒ ௏٘ оةࢿ੉ ڄয૓׮
  10. एযоח ௏ց.. ੉ۡ ٸ উ٘۽੉٘ ѐߊ੗ੋ ѱ ࠗՍۣ׮ যו զ,


    ৖૘ ஘ҳ ইٜ ৖ ز֎ CTOܳ ݅աҊ ৡ ੉ࢎש੉
 աܳ ࣑ࠗܰ׮.
  11. Ҋࣻۄݶ ࠁా ݻ ୌ઴ ੿ب ח ૞ࠌ׮؍ؘ.. ೵.. WTF?! ޤঠ

    Ӓ ੿بب ޅ ೧ࠄ Ѣ৓য? Dilbert © 2018, Andrews McMeel Syndication
  12. Fat Activity/Fragment - ݅ঈ੄ Ӕਗ ৈӝࢲ ੘֙੄ ࠂण: ৵ Android

    MVCח աࢂо? • Activityо ೡ ࣻ ੓ח ੌ • ۄ੉೐ࢎ੉௿ ҙܻ, ݽٚ UI ۽૒ - ۨ੉ইਓ ࢤࢿ, ۪؊݂, গפݫ੉࣌, Shared Preferences, ౵ੌ IO, ചݶ ੹ജ, ӂೠ ࢸ੿, Loader, Ӓ ৻ী ࣻ ߔ о૑ • ӝࠄ Android Architectureীࢲ Activityۆ? • Controller + View + alpha + omega = god • Fragmentب Ӓր ੘਷ नੌࡺ..
  13. Non-MVC੄ ࢸ҅ ੹ۚ • Non-MVCীࢲ Activityח ޖ঺ੋо? → Activityח ஶ౟܀۞!

    (ӒѪب ই઱ ઁೠ੸ੋ..) • MVP੄ (Ҿӓ੸) ੽Ӕߨ • Activityীࢲ View৬ Controller੄ ৉ೡਸ ୭؀ೠ ࡐ঒ই View৬ Presenter۽ ֈӣ. 
 Activityח ࣽࣻ flow ҙܻ ৉ೡ ਤ઱ • MVVM/Redux ١੄ ੽Ӕߨ • ݃ଲо૑۽ Activityח ୭؀ೠ ੌࠗ context ੄ઓ ӝמ݅ ೞب۾.. 
 View logic਷ ୭؀ೠ data bindingਵ۽ ҳഅ • ৈӝࢲ ੄ޙ: ৵ ҳӖ਷ (ߓ਋ӝب য۵Ҋ Rxо হਵݶ ઁ؀۽ ҳഅب উ غח) ViewModel݅ਸ AAC(Android Architecture Component)ীࢲ ૑ਗೞחо? • ӝઓ Activity/Fragment੄ ഋకܳ ӵڰܻ૑ ঋਵݶࢲ ੤ࢎਊࢿ/ࢤ࢑ࢿ ֫਷ ইఃఫ୊ܳ ҳഅ оמೞӝ ٸޙ* ※઱੄: য٣ө૑ա ୶ஏੑפ׮.
  14. Model-View-Presenter? • 1990֙؀ ୡ IBMীࢲ ୭ୡ۽ ҳഅ • 2006֙ Martin

    Fowler੄ ࣗѐ۽ օܻ ঌ۰૗
 ଵઑ: GUI Architectures
 https://martinfowler.com/eaaDev/uiArchs.html • ࢎप উ٘۽੉٘ ୡӝࠗఠ ҳ੹ਵ۽ ੹೧ઉ ৳؍ ইఃఫ୊ • Ӕؘ ੉޷ ೠޛ р ҳઑ ইצо? ই૒ب ॳաਃ? • ৘, ই૒ب ݆੉ ॺפ׮. ৘ܳ ٜݶ, э਷ ഥࢎоਃ.
  15. Presenter View Model ࢎਊ੗ ੑ۱ਸ ాࠁ ؘ੉ఠ јन ਃ୒ ؘ੉ఠ

    ߸҃ ాࠁ ࠭ ߸҃ ਃ୒ • ݽٚ Presentational Business Logicਸ Presenterীࢲ ୊ܻ • Viewח Presenter੄ ਃ୒ী ٮۄ ࣻز੸ਵ۽ UIܳ ୊ܻೣ
  16. Google Architecture Blueprint۽ ࠙ࢳ೧ࠁח MVP੄ ೨ब • https://github.com/googlesamples/android-architecture/tree/todo- mvp/ •

    Contractor Pattern • View, Presenterח interface ഋక۽ ࢲ۽ܳ ଵઑ • V৬ P੄ ҳഅ੉ ࢴ੉Ѣա, Pо ೒ۖಬ ੄ઓ੸ੋ APIܳ ૒੽ ੽Ӕೡ ৈ૑ܳ ਗୌ ࠉࣧ
  17. /** * This specifies the contract between the view and

    the presenter. */ public interface TasksContract { interface View extends BaseView<Presenter> { // ... void setLoadingIndicator(boolean active); void showTasks(List<Task> tasks); void showAddTask(); void showTaskDetailsUi(String taskId); } interface Presenter extends BasePresenter { // ... void loadTasks(boolean forceUpdate); void addNewTask(); void openTaskDetails(@NonNull Task requestedTask); void completeTask(@NonNull Task completedTask); void activateTask(@NonNull Task activeTask); void clearCompletedTasks(); void setFiltering(TasksFilterType requestType); TasksFilterType getFiltering(); } } • TODO জ੄ п ੘স(task)ܳ ࠁৈ઱Ҋ ୶о ೞח ചݶਸ ਤೠ TasksContractor interface ੿੄ • View-Presenter р੄ ૒੽ োѾਸ Ր਺ • Good?!
  18. • ׮द ೠ ߣ ੗ࣁ൤ ࠇद׮. • যۄ? Presenter੄ ݫٜࣗ٘ਸ

    ࠁפ ؘ ੉ఠܳ ֈѹ઱ח Ѫٜ੉ ੓֎? • Ӓۢ ࢚క ੿ࠁܳ Viewо ыח׮ח ফ ӝ?! /** * This specifies the contract between the view and the presenter. */ public interface TasksContract { interface View extends BaseView<Presenter> { // ... void setLoadingIndicator(boolean active); void showTasks(List<Task> tasks); void showAddTask(); void showTaskDetailsUi(String taskId); } interface Presenter extends BasePresenter { // ... void loadTasks(boolean forceUpdate); void addNewTask(); void openTaskDetails(@NonNull Task requestedTask); void completeTask(@NonNull Task completedTask); void activateTask(@NonNull Task activeTask); void clearCompletedTasks(); void setFiltering(TasksFilterType requestType); TasksFilterType getFiltering(); } }
  19. /** * Display a grid of {@link Task}s. User can

    choose to view all, active or completed tasks. */ public class TasksFragment extends Fragment implements TasksContract.View { private TasksContract.Presenter mPresenter; //... TaskItemListener mItemListener = new TaskItemListener() { @Override public void onTaskClick(Task clickedTask) { mPresenter.openTaskDetails(clickedTask); } @Override public void onCompleteTaskClick(Task completedTask) { mPresenter.completeTask(completedTask); } @Override public void onActivateTaskClick(Task activatedTask) { mPresenter.activateTask(activatedTask); } }; //... private static class TasksAdapter extends BaseAdapter { private List<Task> mTasks; private TaskItemListener mItemListener; public TasksAdapter(List<Task> tasks, TaskItemListener itemListener) { setList(tasks); mItemListener = itemListener; } } } • Bingo! - п ࢚కী ٮܲ కझ௼ܳ viewо ౸ױ೧ࢲ ࠁղ઱Ҋ ੓਺ • Ӓ item listenerܳ ഐ୹ೞח ࠗ࠙ਸ Ѣ ठ۞ ৢۄщ؊פ.. • Task ё୓੄ ࢚కܳ Viewо ыҊ ੓Ҋ, যڃ presenter ೣࣻо ഐ୹غযঠ ೡ ૑ ܳ View Ѿ੿ೠ׮?!
  20. • ೵?! ੉Ѥ MVPо ইפਗ਼ই! • Viewо passiveೞ૑ ঋ׮! •

    গୡী Activityо Controller, Fragment о View੄ ৉ೡਸ ೞب۾ ݅ٚ Ѫ ੗୓о, ੌ ੿ ӏݽ ੉࢚੄ জীࢲח ޙઁо ؼ ࣻ ੓ח ࢸ҅
  21. • ੉۠ য়೧ ٸޙী Martin Fowlerח Presenterۄח ੉ܴਸ ತӝೞҊ Supervising

    ControllerۄҊ ࠗܳ Ѫਸ ઁউ. (ӒܻҊ Viewח Passive View ۽ ܴࠗ) • Ref: Retirement note for Model View Presenter Pattern
 https://martinfowler.com/eaaDev/ModelViewPresenter.html .
  22. ؊ ੗ࣁೠ Ѥ… ৵ Viewח Passive ೧ঠೞחо, ӒܻҊ ߄ۈ૒ೠ View৬

    Presenter੄ ৉ೡ਷ ޖ঺ੋо? ࣘदਗೞѱ ঌ۰٘݀פ׮… (ই݃ب)
  23. • ఋ ইఃఫ୊ীب ੸ਊغח ফӝ݅ ೞ੗ݶ, • Android੄ ҃਋, nested

    ҳઑ۽ т ࣻ߆ী হ਺. • Ӓۢ ҳӖ਷ ৵ ইఃఫ୊ ୒ࢎ૓ਸ ੉ۧѱ ૧ਸ ө? • ઱੄੼: ౠ੿ ഥࢎ੄ ҕध ࢠ೒਷ যڃ ੄بܳ о૑Ҋ ٜ݅য ૕ ࣻب ੓׮ח ੼ਸ ޷ܻ ৏ف ী ل ೙ਃо ੓਺ P V M Home MVP* P V M Banner MVP P V M Original List MVP P V M Preview List MVP ※઱੄: য٣ө૑ա ୶ஏੑפ׮.
  24. MVVM • MVVMীࢲ Viewח ־ҳੋо? • XML! DataBinding! • XMLী

    view logicਸ ನೣ 
 → Declarativeೠ UI ۽૒ ҳഅ੉ оמ
 → BindingAdapter ઑ೤, RxJava/ RxBinding੄ ب਑ਵ۽ View੄ ࢚׼ࣻ ҳഅਸ Activity/Fragment۽ࠗఠ ࡐ঒ ই ৢ ࣻ ੓਺ http://kyubid.com/blog/understanding-mvvm-on-android-tutorial-05-introduction-to-reactive-programming-with-rxjava/
  25. • ViewModel • Ӓ ੗୓۽ ة݀੸ੋ दझమ • Viewী ੽Ӕೡ

    ࣻب হҊ, ઓ੤ ੗୓ب ݽܴ • AAC੄ ViewModel • LifeCycle ૑ਗ ӝמ ੉৻ী ౠ߹ೠ ӝמ হ਺ (ରӝ ߡ੹ীࢲب SavedStateо ୶оغח ੿ ب) • ૒੽ Life Cycle ୊ܻܳ ҳഅೞҊ AAC-ViewModelਸ ࢎਊೞ૑ ঋইب ޖߑ • Pro tip: MVVM ҳઑ ࢸݺীࢲ AAC Ӓܿࠗఠ աয়ח Ӗ੉ۄݶ ޺Ҋ Ѣܰदݶ ؾפ׮
  26. Redux - ୹ߊ੼ • Part I.ীࢲ ফӝ೮٠, ݽ߄ੌ জীࢲ о੢

    ௾ դઁ ઺੄ ೞաח ࠂ੟ೠ ࢚క ٜਸ যڌѱ ӭՔೞҊ ਬ૑ࠁࣻࢿ ֫ѱ ҳഅೡ Ѫੋо੄ ޙઁ • ߊ࢚ਸ ߄Լࢲ জ ੹୓੄ ੉߮౟ܳ State Machineਵ۽ ୊ܻೠ׮ݶ যڄө? • Life Cycle ୊ܻ۽ Ҏݠܻ এਸ ੌ੉ әѺ൤ ઴যٝ • ࢚కী ٮۄ ׮ܰѱ ز੘ೞח UIܳ ࠁ׮ ૒ҙ੸ਵ۽ ҙܻ оמ • ౠ੿ചݶীࢲ ࣻ੿ ػ ղਊ (৘: “જইਃ” ࢚క ߸҃)੉ ׮ܲ Ҕীࢲ ੷੺۽ ੸ਊ
  27. • Ӓؘ۠.. • State Machineਸ ૒੽ ҳഅೞ׮ ࠁݶ.. п ۽૒੄

    ୶࢚ചܳ যڌѱ ೡ ૑ ݆਷ Ҋ޹ ਸ ೞѱ ؽ • ࢚క: ݢ੷ ࢚కܳ ੷੢ೞח ࠗ࠙਷ ࠁా enum class ইפݶ, sealed class۽ ҳഅ • ࢚క ୌ੉(transition/flow): যڃ ઑѤীࢲח B۽, ژ ׮ܲ ઑѤীࢲח C۽ ߸҃ • ۽૒ ࣻ೯: п ࢚కо ߸҃ غ঻ਸ ٸ ࣻ೯೧ঠೡ पઁ ۽૒ • ਤ ࣁ ਃࣗ੄ ࠂ੟بী ٮۄ ࢚ടী ݏѱ ҳഅ೧ঠೞ૑݅ о੢ ߧਊ੸ੋ ߑߨ ઺ ೞա ח uni-directionalೠ pipeline ഋక -> ߄۽ Flux ҳઑ!
  28. MVI? Flux? Redux? • Flux: Facebookীࢲ, ਢ ೐ۿ౟ূ٘੄ ࢚క ୊ܻܳ

    ૒ҙ੸੉Ҋ ӭՔೞѱ ೞӝ ਤ ೧ Ҋউೠ Architectural Pattern. ױߑೱ੄ pipelined loopܳ ా೧ ੉߮౟ܳ ୊ܻ • MVI: Fluxী View ୊ܻ ١ ݽ߄ੌ ҙ۲ ղਊਸ ୶о೧ࢲ ࠗܰח ੉ܴ. উ٘۽੉٘ ѐߊীࢶ Flux৬ э਷ ਊযۄҊ ࢤп೧ب ޖߑ • Redux: Flux ಁఢ੄ ߸ഋ ҳഅ୓ ઺ о੢ ബਯ੸੉ۄҊ ঌ۰૓ ҳഅ୓. (ޛۿ Java Script۽..) - immutable state, single source of truthܳ पഅೠ ױࣽೠ ҳഅ • Dan Abramovۄח ੻਷ ѐߊ੗о Ҋউ. 100ৈ ઴ী ࠛҗೠ ۄ੉࠳۞ܻ۽ ݽٚ Flux ҳഅ୓ܳ ಣ੿ -> flux ਗ Ҋউ੗ীѱ ੋ੿ ߉਷ റ, ߄۽ Facebookীࢲ झ ஠ਓ
  29. • Action: ࢚కܳ ߸҃ೞۄח ݺ۸݅ਸ о૗ • ࠁా਷ Action Creatorܳ

    ా೧ ٜ݅য૗ • State: ࢚క੄ ؘ੉ఠ݅ਸ о૗. no logic • immutable (fluxח mutable) • Store • ࢚క੄ ੷੢ࣗ • ࢚కܳ ߸҃दఃҊ, ా૑ ೞח ৉ೡ • RxJava ഑਷ Coroutineਵ۽ ࣚऔѱ ҳഅ оמ • Reducer • ࣽࣻ ೣࣻ(pure function) ഋక۽ ࢚క ߸҃ਸ ҳ അ: (State, Action) -> new State Ӓܿ ୹୊: https://speakerdeck.com/yuyakaido/droidkaigi-2019
  30. Ӓۢ side effect ୊ܻח ؀୓ ־о? → Middleware! Ӓܿ ୹୊:

    https://speakerdeck.com/yuyakaido/droidkaigi-2019
  31. Redux੄ ੢ױ੼ • ੢੼ • ࢚క ୊ܻীࢲ੄ ۄ੉೐ ࢎ੉௿੄ ৔ೱਸ

    যו ੿ب ߓઁೡ ࣻ ੓਺ • ചݶীࢲ back ߡౡ ־ܲ റী ٍןѱ ߊࢤೠ API ী۞.. э਷ গݒೞҊ դ೧ೠ ࢚ടب ബҗ੸ਵ۽ ؀୊ оמ • ࢚క੄ ੿੄ ࠗ࠙, ੷੢ ࠗ࠙, ୊ܻ ࠗ࠙੉ ৮߷൤ աׇઉ ੓ӝ ٸޙী ࣻ੿/ഛ੢੉ ӓب۽ ಞೣ • Functionalೠ ҳઑ੄ ౠࢿ࢚ ਬ׫ పझ౟ܳ ੘ࢿೞח Ѫ੉ ӓب۽ ಞܻೣ • Debugging੄ नࣁ҅! അ੤੄ ݽٚ ੹৉੸ ࢚కܳ ഛੋೡ ࣻ ੓Ҋ, ࢚క ߸ࣻ чਸ ૒੽ ࣻ੿೧ࢲ ੹୓ ࢚కܳ ߄Լࠅ ࣻب ੓਺ • ױ੼ • ࢚׼ೠ ࣻળ੄ ೟ण ࠺ਊ੉ ࣗਃ • ௏٘۝ ૐо, ౠ൤ boiler plate ௏٘੄ ߈ࠂ੸ ࢤ࢑਷ ೖೞӝ য۰਑
  32. Flux / Redux੄ അ੤৬ ޷ې • അ੤ • ReKotlin, RxRedux੉

    ੓ਵա അ੤۽ࢶ ૒੽ ҳഅਸ ୶ୌ • State / Action੄ ੽੼ਸ View۽ ೡ ࣻب ੓૑݅ ViewModel۽ب оמ • ӒܻҊ Flux੄ ҃਋ח Storeܳ ViewModel۽ ҳഅ! • RxJava۽ Store, ӒܻҊ side effectܳ ୊ܻೞח middlewareܳ ҳഅ vs Coroutine + LiveData ઑ೤ • ޷ې? • Rxܳ Ҷ੉ ॳ૑ ঋইب غח use caseо ؀ࠗ࠙੉Ҋ, coroutine ജ҃੉ ࢿࣼ/উ੿ച ؽী ٮۄ әѺ൤ coroutineਵ۽ ઺ब੉ ֈযт ٠ • അ੤ ઱ܨੋ Redux-Thunk middlewareܳ Redux-Sagaо ؀୓ೡ Ѫਵ۽ ৘࢚ • Coroutineҗ ৮߷ೞѱ ݒ஖ غח async loop ҳઑ • ӓب۽ ইܴ׹Ҋ ӭՔೠ పझ౟ ௏٘ ੘ࢿ оמ
  33. 1. Multi-module! • ৈӝࢲ ਫ਼द ૕ޙ • internal class (inner

    class ইש) ੉ ޖ঺ੋ૑ ইदաਃ? • private / protected / internal / public ઺ internal - public੄ ର੉ח? • internal ध߹੗ -> ׮ܲ module (packageо ইש) ীࢲ ࠁ੉૑ ঋѱ ೣ • android gradle plugin 3.0.0ࠗఠ compile -> implementationਵ۽ ߄Ո ੉ਬ о ޖ঺ੋ૑ ইदաਃ? • ݣ౭ ݽٕ ૑ਗ ӝמ੉ ъച غݶࢲ ୶оػ ѐ֛ • ੿ഛ൤ח, compile == api ۽ ߄Պ
  34. ଵઑ оמ • Compile (== api) ध߹੗ • ౠ߹൤ ૑੿ೞ૑

    ঋইب ࣚ੗ ݽٕө૑ ଵઑ оמ • ߄Լ ফӝೞݶ, module2о ߸҃੉ غ ݶ app ݽٕب ੤ஹ౵ ੌ ೧ঠೣ Ӓܿ ୹୊: https://speakerdeck.com/sansanbuildersbox/multi-module-android-application
  35. ଵઑ ࠛо • implementation ध߹੗ • ݺद੸ਵ۽ ૑੿ೞ૑ ঋ ਷

    ࣚ੗ ݽٕ ଵઑ ࠛо • ߄Լ ফӝೞݶ, module2о ߸҃੉ غ যب app ݽٕ਷ ஹ౵ ੌೡ ೙ਃо হ਺ Ӓܿ ୹୊: https://speakerdeck.com/sansanbuildersbox/multi-module-android-application
  36. • ݣ౭ ݽٕ਷ ৵ ॳחо? • അप੸ੋ ੉ਬ: ࠽٘ ࣘب

    • ಽ ࠽٘: 36.4s → 30s, incremental build: 14.2s → 7s • Ref: https://speakerdeck.com/sansanbuildersbox/multi-module-android- application • ৵? ઱ػ ੉ਬח annotation processing. kapt੄ ҃਋ח ই૒ب incremental processingਸ ૑ਗೞ૑ ঋ਺. • Ӓ৻ realmҗ э੉ byte code weavingਸ ೞח ۄ੉࠳۞ܻܳ ߹ب ݽٕ۽ ࡐח Ѫ ݅ਵ۽ 30% ࠽٘ ࢿמ ೱ࢚ • ബਯ੸ੋ ࠙স ೐۽ࣁझ оמ: ݽٕ ߹۽ ҳഅ੄ Ѻܻ / పझ౟о оמ • ة݀੸ੋ ࢸ҅ܳ ୢ૓
  37. • ݽٕ਷ যڌѱ ա־חо? - (1) Layer ߹ ࣻ૒ ܻ࠙

    • Presentation / Domain / Data Layer • ױ, Applicationীࢲ DBܳ ࢤࢿ೧ঠ ೞӝ ٸޙী, P -> D -> L ഋక੄ ߓ஖ח ࠛоמ • app਷ DIܳ ੿੄, ui / data ݽٕী domain ݽٕ੉ ઱ੑؼ ࣻ ੓ب۾ ೣ Ӓܿ ୹୊: https://speakerdeck.com/sansanbuildersbox/multi-module-android-application
  38. • ݽٕ਷ যڌѱ ա־חо? - (2) ࣻಣ ܻ࠙ • ചݶ߹

    / ӝמ߹۽ ܻ࠙ → feature߹ ة݀ࢿ ഛࠁ • ੄ઓࢿ ӝળ ܻ࠙: Realm ١ black magic ҅੄ ӝࣿ੉ ࢎਊػ ࠗ࠙਷ ӓ۱ ߹ب ݽٕ۽ ܻ࠙ • Eg. SanSan Eight App੄ ҃਋, realm object੄ ߹ب ݽٕ ܻ࠙݅ਵ۽ ಽ ࠽٘ दр੉ 6m 46s → 4m 27s • ઱੄੼: ࢚ഐ ଵઑ • উ٘۽੉٘ ݽٕ੄ ଵઑח ױߑೱ݅ ೲਊೞ޲۽ নߑೱ੄ ଵઑо ࠛо • ف ѐ੄ ചݶ੉ п੗ ࢲ۽ܳ द੘ೡ ࣻ ੓ח ҃਋ח, п੗੄ intentܳ оઉঠ ೞ޲۽ ܻ࠙о ࠛоמ೧૗ • Intent ࢤࢿ ੋఠಕ੉झ݅ਸ ыҊ ҳഅ਷ ୭࢚ਤ ݽٕ(:app)੉ ࣗਬ → DI۽ ঳যয়ӝ • ઺ঔ૘઺ध navigation ௿ېझܳ ٜ݅Ҋ п ݽٕ਷ ੋఠಕ੉झ݅ ыب۾ ҳഅ (DroidKaigi 2018 জ ଵઑ) • Tip: Daggerܳ ੉ਊೠ ઱ੑ + ࢎਊ੗ ౵ۄ޷ఠо زदী ೙ਃೠ ҃਋ۄݶ, AssistedInjection ਸ ࢎਊ
  39. • Dependency Inversion: ੉ઁө૑ Androidীࢲ ઺ਃद ػ ੸ হ؍ ࢸ҅

    ਗ஗ • ࢚ਤ ݽٕ਷ ೞਤ ݽٕী ੄ઓࢿ੉ ੓যࢲח উ ػ׮ & ࢚ਤ ݽٕ ೞਤ ݽٕ ݽف ੋఠಕ੉झী݅ ੄ઓೠ׮ • A ё୓о B ё୓੄ ۨಌ۠झܳ ૒੽ ଵઑೞח ؀न, interfaceܳ ଵઑೞৈ ҳഅ ੄ઓࢿਸ Ր਺ • Bо ߸҃غযب Aח ஹ౵ੌೡ ೙ਃо হ਺ • زੌೠ ੋఠಕ੉झܳ ы૑݅ ੹ഃ ׮ܲ ۽૒ਵ۽ ҳഅػ ઁ3੄ ݽٕ۽ औѱ ߸҃ оמ 
 → Dependency Injection੄ ب਑ਸ ߉ਵݶ п ݽٕ ߹ ࢸ੿ਸ ੌҙػ ߑधਵ۽ ࣚऔѱ ࣻ੿ оמ
  40. 2. RxJava vs Coroutine vs LiveData • ৵ ೙ਃೠо? •

    Reactive: ࠺زӝ੸ੋ ୊ܻܳ imperativeೞѱ ୊ܻೡ ࣻ ੓ѱ ೧ષ • RxJava • ৈ੹൤, Androidীࢲ੄ ࠺زӝ ୊ܻ ਤೠ അઓೞח о੢ ъ۱ೞҊ ಞܻೠ ࣻױ • Androidীࢲ੄ ࠂ੟ೠ ࢚క୊ܻܳ ૒ҙ੸ਵ۽ ҳഅ оמ • View - ViewModelҗ੄ оҮܳ ਤೠ black magic झ۞਍ ׮নೠ ҳഅب оמ • eg. ࢚ടী ٮۄ ࣽର੸ਵ۽ प೯೧ঠ ೞח গפݫ੉ٜ࣌ਸ пп Completable۽ ੿੄ೠ റ, Combine೧ࢲ प೯
  41. • ੉۠ Ѫب оמ! • ViewGroup੄ ઺੼੉ ߄Չ ٸ݃׮ ViewModel੉

    ా૑ܳ ߉ਸ ࣻ ੓ب۾ View ஏীࢲ ഐ୹ೡ ࣻ ੓ח ೾ಌ ೣࣻ internal fun createVerticalCenterPublisher(layout: View): Observable<Int> = Observable.create<Int> { emitter -> emitter.onNext(layout.bottom - layout.top) val callback = View.OnLayoutChangeListener { _, _, top, _, bottom, _, _, _, _ -> emitter.onNext(bottom - top) } layout.addOnLayoutChangeListener(callback) emitter.setCancellable { layout.removeOnLayoutChangeListener(callback) } }.subscribeOn(AndroidSchedulers.mainThread()) .throttleLatest(100, TimeUnit.MILLISECONDS, true) .map { it / 2 }
  42. Coroutine • ޤо જ਷о? • ࢿמ ੉੼: coroutine is light-weight

    threads • Rxࠁ׮ ؏ য۵׮ • ࠁ׮ functionalೠ ҳഅ - Saga ಁఢ э਷ ഋక੄ ҳഅী ఌਘ • ੉ઁח উ੿ӝী ੽যٜ঻਺ - Kotlin 1.3җ ೣԋ ੿ध ߡ੹੉ غ঻Ҋ, ୭न ࢎনী ݏ୸ ׮নೠ ૑ ਗ੉ ৘੿غয ੓਺. • lifecycle-viewModel-ktx 2.1.0 (അ੤ alpha03)ࠗఠ lifecycle-awareೠ Coroutine Scope ੋ viewmodelScopeܳ ҕध ૑ਗ • retrofit ରӝ ߡ੹ীࢲ “suspend fun”ਸ ഋక۽ api interface ੿੄ оמ (അ੤ “Deferred”ܳ ܻఢೞח ഋక)
  43. LiveData • LiveDataী ؀೧ ֤ೞӝ ੹ী.. • View - ViewModel

    (or Presenter) р੄ ੉߮౟ ా૑ী ੓যࢲ о੢ ੉࢚੸ੋ ੉ ߮౟ ా૑ ੹׳੗ח যڃ ౠ૚ਸ оઉঠೡө? • ੉߮౟ ੹׳੉ UI झۨ٘ীࢲ ੉ܞઉঠ ೠ׮ • Side Effect੄ ҕਬо оמ೧ঠೠ׮. -> ए਍ ݈۽ ೞݶ ೞա੄ ੉߮౟ܳ ৈ۞ ੉ ߮౟ ೩ٜ۞о ҕਬೡ ࣻ ੓যঠ ೠ׮ • ী۞ܳ skip ೡ ࣻ ੓যঠ ೠ׮ • → RxSwift੄ ҃਋, Signal/Driverо ੉ী ೧׼
  44. • LiveData੄ ౠ૚ • ӝࠄ੸ਵ۽ UI threadীࢲ ز੘ • Side

    Effect(ч੄ ߸ച, ੉߮౟)੄ ҕਬо оמ • Configuration ߸҃ द ݃૑݄ ߊࢤೠ ੉߮౟ܳ replay ೧ષ (ױ, ੄ب஖ ঋ਷ ߡӒо ࢤӡ ৈ૑ ੓਺) • transformationਸ ా೧ RxJava੄ combineҗ ࠺तೞѱ ҳഅ оמ • → RxSwift੄ Driver৬ ਬࢎೠ ѐ֛ + LifeCycle-awareness • LiveDataח ঱ઁ ॳחо? • Rx੄ ؀୓੤о ইצ ࠁ৮੤ • DataBinding ਊب۽ח ୶ୌೞ૑ ঋ਺
  45. ࢶ੿ ઑѤ • জ ӏݽ: Toy projectо ইפҊ पઁ Play

    Storeী ৢۄৡ জੋо • ࢸ҅: Clean Architecture ١੉ ੜ ੸ਊغয ੓חо • పझ౟: Unit Testо ਃࣗਃࣗ ੜ ҳഅغয ੓חо • ௏٘ ಿ૕: ղ ೐۽ં౟ীب ы׮ ॶ݅ೠ ಴അ੉ ݆਷о
  46. Google IO 2018 • https://github.com/google/iosched • Clean Architecture - Domain

    layer੄ UseCase ҳഅ ߂ పझ౟ • LiveData ࢎਊ੄ ૓ࣻ: RxJava ইפݶ উ ؼ Ѫ э਷ ӝמٜө૑ب ކٶ MediatorLiveData۽ ҳഅ! • ઱੄ೡ ੼: LiveDataܳ पઁ۽ ੷ۧѱ ॳח Ѫ਷ ӓ۱ ࠺୶ୌ • ӝఋ ইఃఫ୊ ৻੸ਵ۽ ࣁࠗ ௏٘ ҳഅী ଵҊೡ ੼੉ ݒ਋ ݆਺
  47. DroidKaigi 2018 • https://github.com/DroidKaigi/conference-app-2018 • о੢ ݽߧ੸ੋ MVVM ҳઑ •

    о੢ ഴܯೞҊ ӭՔೠ Dagger ੿੄ • Domain ۽૒਷ Data ۨ੉য੄ Repository ಁఢਵ۽ ҳഅ • NavigationController - ݒ਋ ഴܯೠ coordination ؀উ • gradle kts
  48. DroidKaigi 2019 • https://github.com/DroidKaigi/conference-app-2019 • ݣ౭ ݽٕ ҳഅ • +

    iOSب ૑ਗ • Flux ҳઑ • Dagger ഛ੢ • AssistInjection! • ୭न UI ҳഅ! - Custom LayoutManager੄ જ਷ ৘ܳ ࠅ ࣻ ੓׮!
  49. I’ll be back! • DroidKnights 2020 উ٘۽੉٘ ইఃఫ୊ ࣁߣ૩ दܻૉ۽

    جই২פ׮. 
 ղਊ਷ ই݃ب.. • Coroutine + Arrow۽ ҳഅೠ functionalೠ Redux ҳઑ बக ࠙ࢳ • ؀ӏݽ Multi-module ೐۽ં౟ ҳ୷ • Dagger ࢎਊಁఢ ୨੿ܻ • (ѐ੼ോস ઺੉؍) ࠶۽Ӓ ੤ѐ೤פ׮! - 4/20ࠗఠ • पઁ ೐۽ં౟ীࢲ ੄޷੓ח Test-Driven Development • Dagger 2 Dependency Injection ҳഅ ੹ۚ ୨੿ܻ ъࢎܕ Email: [email protected] Blog: https://medium.com/@justfaceit Slide: https://speakerdeck.com/saryong