Pro Yearly is on sale from $80 to $50! »

Navigationを見据えたリファクタリング -マルチモジュール化を添えて-

Navigationを見据えたリファクタリング -マルチモジュール化を添えて-

Bonfire Android #5
2019/8/19

9d4a459864f822fb5aa7a5741e60e26b?s=128

Keisuke kiuchi

August 19, 2019
Tweet

Transcript

  1. OBWJHBUJPOΛݟਾ͑ͨϦϑΝΫλϦϯά
 dϚϧνϞδϡʔϧԽΛఴ͑ͯd #POpSF"OESPJE ໦಺ɹܒี 

  2. ໦಺ܒี w ৬ۀɿ:ͷ"OESPJEΤϯδχΞ݉ҭࣇύύ w झຯͰ࡞ͬͨϞϊɿʮΒ͘ͰΜ "QQ ʯɺ
 ʮ$MFBO"SDIJUFDUVSF5FNQMBUF'PS,PUMJO 044 ʯ

    w ޷͖ͳΞʔΩςΫνϟɿ$MFBO"SDIJUFDVUF w 4/4
 5XJUUFS!GFJ@LPNF
 (JUIVC!LJVDIJLFJTVLF
 2JJUB!L@LFJTVLF
  3. એ఻ͦͷ̍ w ٕज़ॻయ  ʹͯαʔΫϧඈཾ͞Μ͔ͪΒ
 ʮϥϊϕ෩ʹ
 $MFBO"SDIJUFDUVSFΛֶͿຊʯ
 తͳಉਓࢽग़͠·ʔ͢

  4. એ఻ͦͷ̎

  5. ࠓճͷωλ ϑΝΠφϯεΞϓϦΛ͕ͬͭΓ
 ϦϑΝΫλϦϯά͠Α͏ͱͨ࣌͠ͷग़དྷࣄ ґଘؔ܎ ࢖༻ؔ܎

  6. "QQ ͜Μͳײ͡ͳ΍ͭΛɾɾɾ 1SFTFOUFS %BUB

  7. ͜Μͳײ͡ʹ͍ͨ͠ "QQ 1SFTFOUFS %BUB %PNBJO 'SBHNFOU 'SBHNFOU 'SBHNFOU OBWJ HBUJPO

    ɾ ɾ ɾ
  8. 1SFTFOUFS OBWJHBUJPOಋೖ͢Δ্Ͱݟ͖͑ͯͨ໰୊఺ w BQQ഑Լͷ'SBHNFOU͕OBWJHBUJPO͔Βݟ͑ͳ͍ w Ϋϥεؒͷ૬ޓґଘ͕ଟ͘શΫϥε͕͓Ҿӽ͢͠Δ੎͍ͩͬͨ w ը໘ભҠܥͷॲཧ͕৭ΜͳॴʹࢄΒ͹͍͙ͬͯͯ͢ʹ͸ಋೖͰ͖ͳ͔ͬͨ "QQ 'SBHNFOU

    'SBHNFOU ɾ ɾ ɾ 'SBHNFOU OBWJ HBUJPO 'SBHNFOU 'SBHNFOU 'SBHNFOU 'SBHNFOU TPNF$MBTT TPNF$MBTT TPNF$MBTT TPNF$MBTT
  9. ં஭Ҋʜ

  10. কདྷOBWJHBUJPOΛಋೖ͠΍͍͢ Α͏ʹϦϑΝΫλϦϯά͠Α͏

  11. ΍ͬͨ͜ͱ ґଘͷ޲͖Λٯసͤͭͭ͞ OBWJHBUJPOʹؔ࿈͢ΔॲཧΛू໿ͨ͠

  12. ͜ΕΛɾɾɾ w 3FGBDUPSFE'SBHNFOU͔Β͸'SBHNFOU ͕ݟ͑ͳ͍ 1SFTFOUFS "QQ 3FGBDUPSFE
 'SBHNFOU 'SBHNFOU ɾ

    ɾ ɾ 'SBHNFOU
  13. ͜͏ͨ͠ w /BWJ*OUFSGBDFΛ௨ͯؒ͠઀తʹ'SBHNFOU ΁ΞΫηεͰ͖ΔΑ͏ʹͨ͠ 1SFTFOUFS "QQ 3FGBDUPSFE
 'SBHNFOU 'SBHNFOU ɾ

    ɾ ɾ 'SBHNFOU /BWJ
 *OUFSGBDF /BWJ
 *OUFSGBDF
 *NQM
  14. 1SFTFOUFS "QQ ࣮૷ interface NaviInterface { fun getFragment2(): Fragment fun

    getFragment3(data: SomeData): Fragment } class RefactoredFragment { override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { android.R.id.home -> changeFragment(naviInterface.getFragment2()) R.id.action_sub -> changeFragment(naviInterface.getFragment3(data)) } return super.onOptionsItemSelected(item) } } class NaviInterfaceImpl : NaviInterface { override fun getFragment2(): Fragment = Fragment2.newInstance() override fun getFragment3(data: SomeData): Fragment = Fragment3.newInstance(data.code, data.name) } OBWJHBUJPOΛ࢖͏ͱ͖͸͜ΕΒΛ ஔ͖׵͑Ε͹0, ͩͱࢥ͏ OBWJHBUJPOʹ͢Δ࣌͸
 ͜ΕΒΛஔ͖׵͑Ε͹0,
  15. OBWJHBUJPO༻ͷॲཧ͕ू໿ग़དྷͯ
 1SFTFOUFS͕BQQʹґଘ͠ͳ͘ͳͬͨ

  16. ऄ଍ͦͷ̍ w ͜ͷख๏ͬͯଞͷϨΨγʔͳ"QJ΍6UJMݺͼग़͠ʹ΋࢖͑ΔΜ͡Όʁ
 ˠ:&4 1SFTFOUFS "QQ 3FGBDUPSFE
 'SBHNFOU -FHBDZ6UJM ɾ

    ɾ ɾ -FHBDZ"QJ -FHBDZ
 *OUFSGBDF -FHBDZ
 *OUFSGBDF
 *NQM -FHBDZ
 *OUFSGBDF -FHBDZ
 *OUFSGBDF -FHBDZ
 *OUFSGBDF
 *NQM -FHBDZ
 *OUFSGBDF
 *NQM
  17. ऄ଍ͦͷ w ͦ΋ͦ΋OBWJHBUJPOΛBQQ಺ʹ࣮૷͢Ε͹Α͔ͬͨͷͰ͸ʁ
 ˠ:&4 1SFTFOUFS "QQ 3FGBDUPSFE
 'SBHNFOU 'SBHNFOU ɾ

    ɾ ɾ 'SBHNFOU OBWJ
 HBUJPO
  18. ·ͱΊ w ґଘͷ޲͖Λٯసͤ͞Ε͹ɺ1SFTFOUFSϞδϡʔϧ͔ΒBQQϞδϡʔϧ΁ ͷؒ઀తͳࢀর͕Մೳ OBWJHBUJPOҎ֎ʹ΋৭ΜͳγʔϯͰར༻Մೳ  w ͦ΋ͦ΋OBWJHBUJPOͷ࣮૷ΛBQQϞδϡʔϧͰߦ͑͹ґଘੑΛ
 ؾʹ͠ͳͯ͘ྑ͍

  19. ͓ΘΓ