Slide 1

Slide 1 text

CleanArchitectureϕʔεͰ AndroidΞϓϦͭͬͯ͘Έͨ࿩

Slide 2

Slide 2 text

ࣗݾ঺հ ❖ 2014೥CyberAgent৽ଔೖࣾ ❖ androidྺ2೥ ❖ AMESTAGEͷandroid։ൃΛ୲౰ ❖ झຯɿήʔϜɾΞχϝɾΞΠυϧ ࡾ໺ ߂وʢMino Hirokiʣ

Slide 3

Slide 3 text

AMESTAGE঺հ

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

໨࣍ ❖ CleanArchitectureͱ͸ʁ ❖ CleanArchitectureʹج͍ͮͨAndroid։ൃ ❖ ;Γ͔͑Γ

Slide 6

Slide 6 text

໨࣍ ❖ CleanArchitectureͱ͸ʁ ❖ CleanArchitectureʹج͍ͮͨAndroid։ൃ ❖ ;Γ͔͑Γ

Slide 7

Slide 7 text

CleanArchitectureͱ͸ʁ υϝΠϯۦಈ։ൃʢDDDʣɺϢʔεέʔεۦಈ։ൃʢUCDDʣͳͲΛϕʔεʹఏҊ͞Εͨɺ ֤ػೳ΍੹೚Λͭͷ૚Λ΋ͬͨԁܗͷϨΠϠʔʹ෼͚ɺ֤ϨΠϠʔؒʹґଘؔ܎ͷϧʔϧΛ࣋ͨͤͨઃܭࢥ૝ɻ UIͱϏδωεϩδοΫΛΩϨΠʹ෼͚Δ͜ͱ͕Ͱ͖ɺݻ༗ͷϑϨʔϜϫʔΫ΍σʔλετΞʹ΋ґଘ͠ͳ͍ͱ͍͏ ͷ͕࠷େͷϝϦοτɻ

Slide 8

Slide 8 text

CleanArchitectureͱ͸ʁ 4ͭͷϨΠϠʔ ಺ଆͷԁ΄ͲαʔϏεͷࠜװͱͳΔߴ࣍ͷ֓೦ɻ ֎ଆ͸۩ମతͳ%#΍6*ͳͲɺৄࡉͳ֓೦ɻ

Slide 9

Slide 9 text

CleanArchitectureͱ͸ʁ Enterprise Business RulesʢEntitiesʣ αʔϏεશମʹڞ௨͢ΔϏδωεϧʔϧɻ͜ͷઃܭʹ͓͚Δ࠷΋ߴϨϕϧͷϧʔϧɻ ྫʣAMESTAGEͷ৔߹͸ɺνϟϯωϧ৘ใ΍์ૹ৘ใɺϢʔβʔ৘ใͳͲͷఆٛɻ

Slide 10

Slide 10 text

CleanArchitectureͱ͸ʁ Application Business RulesʢUseCasesʣ ΞϓϦέʔγϣϯݻ༗ͷϏδωεϧʔϧɻʢࠓճͷ৔߹ʣAndroidΞϓϦ͕ඞཁͱ͢ΔϏδωεϩδοΫ͕͜͜ʹೖΔɻ ྫʣ์ૹIDΛݩʹ์ૹ৘ใΛऔಘ͢ΔɺTwitter࿈ܞ৘ใΛݩʹαʔϏεͷೝূΛߦ͏ͳͲɻ

Slide 11

Slide 11 text

CleanArchitectureͱ͸ʁ Interface AdaptersʢControllers/Presenters/Gatewaysʣ UI΍DBͳͲͷ֎෦ػؔͱɺϢʔεέʔε΍ΤϯςΟςΟͳͲͷυϝΠϯ૚ʢαʔϏεͷࠜװʣͱͷؒͷڮ౉͠ͷͨΊͷɺ σʔλม׵Λߦ͏Adapter܈ɻ͜ͷ૚͸UI΍DBʹؔ͢Δ৘ใΛ஌͍ͬͯΔ͕ɺEntity UseCase͸஌Βͳ͍ɻ

Slide 12

Slide 12 text

CleanArchitectureͱ͸ʁ Frameworks & DriversʢWeb / UI / DB …ʣ ͜ͷઃܭʹ͓͚Δ࠷֎૚ɻDB΍UIϑϨʔϜϫʔΫͳͲ͕͜͜ʹଐ͢Δɻ
 FY 42-΍ωοτϫʔΫͷίʔυɺ6*ͷඳըͳͲ

Slide 13

Slide 13 text

CleanArchitectureͱ͸ʁ ґଘؔ܎ͷϧʔϧ ԁͷ֎ଆͷ૚͕಺ଆͷ૚ʹґଘ͢Δɻʢ಺ଆͷ૚͸֎ଆͷ૚ͷ͜ͱΛ஌Βͳ͍ʣ ಺ଆͷ΋ͷ͕֎ଆͷ΋ͷΛར༻͢Δͱ͖͸ɺΠϯλʔϑΣʔεΛఆٛͯ͠ʢ͞ΒʹDIͱ૊Έ߹ΘͤΔ͜ͱʹΑΓʣɺૄͳؔ ܎Λ่͞ͳ͍ɻʢϢʔεέʔε͕DBΛѻ͏৔߹͸RepositoryΠϯλʔϑΣʔεΛఆٛ͢Δʣ

Slide 14

Slide 14 text

໨࣍ ❖ CleanArchitectureͱ͸ʁ ❖ CleanArchitectureʹج͍ͮͨAndroid։ൃ ❖ ;Γ͔͑Γ

Slide 15

Slide 15 text

CleanArchitectureʹج͍ͮͨAndroid։ൃ

Slide 16

Slide 16 text

Activity/Fragment Viewͱͯ͠ͷ໾ׂ→ViewModelͷ৘ใΛը໘ʹදࣔ ίϯτϩʔϥͱͯ͠ͷ໾ׂ→Presenter΁ͷϦΫΤετ ViewModel ֤ը໘ͷঢ়ଶɻ Presenter
 ֤ը໘ݻ༗ͷϩδοΫɻ
 UseCase
 σʔλͷऔಘ΍ߋ৽ͳͲͷϏδωεϩδοΫ Entity
 αʔϏε্ͷ֓೦Λͦͷ··දݱͨ͠Ϋϥε܈ɻ
 Ϣʔβʔ৘ใɺνϟϯωϧ৘ใͳͲɻ
 Repository ӬଓԽσʔλͷग़͠ೖΕɻ "1*΍%#΁ͷΞΫηεΛϥοϓ͢Δɻ API DB API΍ϩʔΧϧDB͔Βͷσʔλͷऔಘɻ CleanArchitectureʹج͍ͮͨAndroid։ൃ

Slide 17

Slide 17 text

CleanArchitectureʹج͍ͮͨAndroid։ൃ Activity/Fragment Viewͱͯ͠ͷ໾ׂ→ViewModelͷ৘ใΛը໘ʹදࣔ ίϯτϩʔϥͱͯ͠ͷ໾ׂ→Presenter΁ͷϦΫΤετ ViewModel ֤ը໘ͷঢ়ଶɻ Presenter
 ֤ը໘ݻ༗ͷϩδοΫɻ
 UseCase
 σʔλͷऔಘ΍ߋ৽ͳͲͷϏδωεϩδοΫ Entity
 αʔϏε্ͷ֓೦Λͦͷ··දݱͨ͠Ϋϥε܈ɻ
 Ϣʔβʔ৘ใɺνϟϯωϧ৘ใͳͲɻ
 Repository ӬଓԽσʔλͷग़͠ೖΕɻ "1*΍%#΁ͷΞΫηεΛϥοϓ͢Δɻ API DB API΍ϩʔΧϧDB͔Βͷσʔλͷऔಘɻ

Slide 18

Slide 18 text

֎෦ͷӬଓԽػߏ͔Βσʔλ͕ฦ͍ͬͯ͘ྲྀΕ͸ɺ RxJavaΛར༻ͯ͠ObservableͷܗͰฦ͢ɻʢίʔυ ͕γϯϓϧʹͳΔͷͰʣ CleanArchitectureʹج͍ͮͨAndroid։ൃ

Slide 19

Slide 19 text

ԁͷ಺ଆ͔Β֎ଆʹ޲͔͏Օॴ͸InterfaceΛఆٛ͠ ͯɺ֎ଆͷΫϥε͸͜ΕΛimplements͢Δɻ
 ͜ΕʹΑΓɺ಺ଆͷΫϥε͕֎ଆͷΫϥεʹґଘ͠ͳ ͍Α͏ʹ͢ΔɻʢDIʹDagger2Λར༻ʣ CleanArchitectureʹج͍ͮͨAndroid։ൃ

Slide 20

Slide 20 text

| |- mobile | | | |- ui | |- user // Activity/Fragment&Presenter&ViewModel | |- UserActivity | |- UserComponent | |- UserPresenter | |- UserView | |- UserViewModel | |- core | |- user
 | |- repository // Repository & Dao /Api | | |- UserRepositoryImpl | | |- UserApi | | |- UserDao | | | |- usecase // UseCase | | |- GetLoginUser | | | |- User // Entity | ύοέʔδߏ੒ CleanArchitectureʹج͍ͮͨAndroid։ൃ

Slide 21

Slide 21 text

CleanArchitectureʹج͍ͮͨAndroid։ൃ ۩ମతͳίʔυͷ঺հ
 αϯϓϧɿϩάΠϯϢʔβʔ৘ใΛදࣔ͢Δը໘

Slide 22

Slide 22 text

| |- core | |- user
 | |- repository // Repository & Dao /Api | | |- UserRepositoryImpl | | |- UserApi | | |- UserDao | | | |- usecase // UseCase | | |- GetLoginUser | | | |- User // Entity | CleanArchitectureʹج͍ͮͨAndroid։ൃ

Slide 23

Slide 23 text

Entity CleanArchitectureʹج͍ͮͨAndroid։ൃ Entityͷ໾ׂ ɾαʔϏεͷࠜװͱͳΔ֓೦ͷఆٛΛߦ͏

Slide 24

Slide 24 text

UseCase CleanArchitectureʹج͍ͮͨAndroid։ൃ UseCaseͷ໾ׂ ɾΞϓϦέʔγϣϯͷϏδωεϩδοΫ ɾThreadͷઃఆɻ࣮ߦ͸ผεϨουɺ݁ՌΛฦ͢ͷ͸ϝΠϯεϨουɻʢ࣮ࡍͷ։ൃͰ͸جఈΫϥεͰߦ͍ͬͯΔʣ ɾϦϙδτϦΛར༻ͨ͠ॲཧɻෳ਺ϦϙδτϦΛར༻͢Δ͜ͱ΋͋Δɻ ɹʮϩάΠϯϢʔβʔΛऔಘ͔ͯ͠ΒϢʔβʔͷνϟϯωϧ৘ใΛऔಘ͢ΔʯͳͲ

Slide 25

Slide 25 text

UseCase CleanArchitectureʹج͍ͮͨAndroid։ൃ UseCaseͷ໾ׂ ɾΞϓϦέʔγϣϯͷϏδωεϩδοΫ ɾThreadͷઃఆɻ࣮ߦ͸ผεϨουɺ݁ՌΛฦ͢ͷ͸ϝΠϯεϨουɻʢجఈΫϥεͰߦ͍ͬͯΔɻίʔυ͸ׂѪʣ ɾϦϙδτϦΛར༻ͨ͠ॲཧɻෳ਺ϦϙδτϦΛར༻͢Δ͜ͱ΋͋Δɻ ɹʮϩάΠϯϢʔβʔΛऔಘ͔ͯ͠ΒϢʔβʔͷνϟϯωϧ৘ใΛऔಘ͢ΔʯͳͲ

Slide 26

Slide 26 text

Repository CleanArchitectureʹج͍ͮͨAndroid։ൃ Repositoryͷ໾ׂ ɾӬଓԽػߏʹର͢ΔγϯϓϧͳΠϯλʔϑΣʔεΛఏڙ ɾ۩ମతͳDB΍APIͷ࣮૷͸ผΫϥεʹఆٛ͠ɺͦΕΛར༻͢Δ͚ͩɻʢDao/Apiͷίʔυ͸ׂѪʣ

Slide 27

Slide 27 text

| |- mobile | | | |- ui | |- user // Activity/Fragment&Presenter&ViewModel | |- UserActivity | |- UserComponent | |- UserPresenter | |- UserView | |- UserViewModel CleanArchitectureʹج͍ͮͨAndroid։ൃ

Slide 28

Slide 28 text

Presenter CleanArchitectureʹج͍ͮͨAndroid։ൃ Presenterͷ໾ׂ ɾUIϩδοΫͷ୲͍खɻUseCaseΛ༻͍ͯɺը໘ͷඳըʹඞཁͳॲཧΛߦ͏ɻ
 ɾUseCaseͷ݁ՌΛViewʹ఻͑Δͱ͖͸ɺViewΠϯλʔϑΣʔεΛఆٛͯ͜͠ΕΛܦ༝͢Δ PresenterͷجఈΫϥεͰߦ͏ॲཧʢίʔυ͸ׂѪʣ ɾڞ௨ͷΤϥʔϋϯυϦϯάʢex. ڧ੍ΞοϓσʔτͷΤϥʔίʔυ͕͖ͨΒμΠΞϩάදࣔʣ ɾSubscriptionͷ؅ཧʢActivity.onDestroyͰ࣮ߦதͷॲཧΛഁغ͢Δʣ

Slide 29

Slide 29 text

ViewModel CleanArchitectureʹج͍ͮͨAndroid։ൃ ViewModelͷ໾ׂ ɾը໘ʹؔ͢Δঢ়ଶΛ͜͜ʹఆٛ͠ɺมߋΛActivity/Fragmentʹ௨஌͢Δ ɾandroid.databinding.Observableʓʓ ͕ศར

Slide 30

Slide 30 text

Activity/Fragment CleanArchitectureʹج͍ͮͨAndroid։ൃ Activity/Fragmentͷ໾ׂ ɾViewModelͷ৘ใΛViewʹඳը͢Δ ɾPresenterʹॲཧΛϦΫΤετ͢Δ
 ʢϥΠϑαΠΫϧɺΫϦοΫΠϕϯτɺetc..ʣ

Slide 31

Slide 31 text

| |- mobile | | | |- ui | |- user // Activity/Fragment, Presenter, ViewModel | |- UserActivity | |- UserComponent | |- UserPresenter | |- UserView | |- UserViewModel | |- core | |- user
 | |- repository // Repository, Dao/Api | | |- UserRepositoryImpl | | |- UserApi | | |- UserDao | | |- UserRepositoryModule | | | |- usecase // Usecase | | |- GetLoginUser | | |- UserRepository | | | |- User // Entity | CleanArchitectureʹج͍ͮͨAndroid։ൃ ҎԼͷ੺จࣈͷΫϥε͸packageείʔϓͰఆٛͰ͖Δ

Slide 32

Slide 32 text

໨࣍ ❖ CleanArchitectureͱ͸ʁ ❖ CleanArchitectureʹج͍ͮͨAndroid։ൃ ❖ ;Γ͔͑Γ

Slide 33

Slide 33 text

;Γ͔͑Γ Α͔ͬͨ͜ͱ ɾ͖Ε͍ʹ͔͚Δ&͋Δఔ౓͓ܾ·Γͷίʔυʹͳͬͯ͘ΔͷͰɺ
 ɹਂ͘ߟ͑ͣʹॻ͚Δ͠ϨϏϡʔ͠΍͍͢ɻ ɾςετॻ͖΍͍͢ʢҰ൪֎ଆҎ֎͸୯७ͳjavaͷςετίʔυ͕ॻ͚Δʣ ɾείʔϓΛݶఆͯ͠ίʔυΛ૊ΊΔͷ͕خ͍͠ ΘΔ͔ͬͨ͜ͱɺେมͩͬͨ͜ͱ ɾ؆୯ͳػೳ௥ՃͰ΋ίʔυྔ͸ଟ͘ͳΔ ɾνʔϜ಺Ͱͷڞ༗ʢGithubͷwikiΛར༻ɻ͋ͱ͸ϨϏϡʔ͠ͳ͕Βʣ

Slide 34

Slide 34 text

CleanArchitectureϕʔεͰAndroidΞϓϦͭͬͨ͘࿩ ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ