Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
CleanArchitecture For Android
Search
MinoHiroki
January 14, 2017
Technology
3
1.9k
CleanArchitecture For Android
CleanArchitectureを参考に、Androidアプリをつくってみたことの紹介
MinoHiroki
January 14, 2017
Tweet
Share
Other Decks in Technology
See All in Technology
TypeScriptの次なる大進化なるか!? 条件型を返り値とする関数の型推論
uhyo
2
1.6k
[FOSS4G 2024 Japan LT] LLMを使ってGISデータ解析を自動化したい!
nssv
1
210
Making your applications cross-environment - OSCG 2024 NA
salaboy
0
180
なぜ今 AI Agent なのか _近藤憲児
kenjikondobai
4
1.4k
CysharpのOSS群から見るModern C#の現在地
neuecc
2
3.2k
100 名超が参加した日経グループ横断の競技型 AWS 学習イベント「Nikkei Group AWS GameDay」の紹介/mediajaws202411
nikkei_engineer_recruiting
1
170
Lambda10周年!Lambdaは何をもたらしたか
smt7174
2
110
The Rise of LLMOps
asei
7
1.4k
ExaDB-D dbaascli で出来ること
oracle4engineer
PRO
0
3.8k
Lexical Analysis
shigashiyama
1
150
誰も全体を知らない ~ ロールの垣根を超えて引き上げる開発生産性 / Boosting Development Productivity Across Roles
kakehashi
1
220
Terraform Stacks入門 #HashiTalks
msato
0
350
Featured
See All Featured
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
How to Think Like a Performance Engineer
csswizardry
20
1.1k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.2k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
Thoughts on Productivity
jonyablonski
67
4.3k
The Invisible Side of Design
smashingmag
298
50k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
120
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
Visualization
eitanlees
145
15k
The Language of Interfaces
destraynor
154
24k
Transcript
CleanArchitectureϕʔεͰ AndroidΞϓϦͭͬͯ͘Έͨ
ࣗݾհ ❖ 2014CyberAgent৽ଔೖࣾ ❖ androidྺ2 ❖ AMESTAGEͷandroid։ൃΛ୲ ❖ झຯɿήʔϜɾΞχϝɾΞΠυϧ ࡾ
߂وʢMino Hirokiʣ
AMESTAGEհ
None
࣍ ❖ CleanArchitectureͱʁ ❖ CleanArchitectureʹج͍ͮͨAndroid։ൃ ❖ ;Γ͔͑Γ
࣍ ❖ CleanArchitectureͱʁ ❖ CleanArchitectureʹج͍ͮͨAndroid։ൃ ❖ ;Γ͔͑Γ
CleanArchitectureͱʁ υϝΠϯۦಈ։ൃʢDDDʣɺϢʔεέʔεۦಈ։ൃʢUCDDʣͳͲΛϕʔεʹఏҊ͞Εͨɺ ֤ػೳΛͭͷΛͬͨԁܗͷϨΠϠʔʹ͚ɺ֤ϨΠϠʔؒʹґଘؔͷϧʔϧΛ࣋ͨͤͨઃܭࢥɻ UIͱϏδωεϩδοΫΛΩϨΠʹ͚Δ͜ͱ͕Ͱ͖ɺݻ༗ͷϑϨʔϜϫʔΫσʔλετΞʹґଘ͠ͳ͍ͱ͍͏ ͷ͕࠷େͷϝϦοτɻ
CleanArchitectureͱʁ 4ͭͷϨΠϠʔ ଆͷԁ΄ͲαʔϏεͷࠜװͱͳΔߴ࣍ͷ֓೦ɻ ֎ଆ۩ମతͳ%#6*ͳͲɺৄࡉͳ֓೦ɻ
CleanArchitectureͱʁ Enterprise Business RulesʢEntitiesʣ αʔϏεશମʹڞ௨͢ΔϏδωεϧʔϧɻ͜ͷઃܭʹ͓͚Δ࠷ߴϨϕϧͷϧʔϧɻ ྫʣAMESTAGEͷ߹ɺνϟϯωϧใ์ૹใɺϢʔβʔใͳͲͷఆٛɻ
CleanArchitectureͱʁ Application Business RulesʢUseCasesʣ ΞϓϦέʔγϣϯݻ༗ͷϏδωεϧʔϧɻʢࠓճͷ߹ʣAndroidΞϓϦ͕ඞཁͱ͢ΔϏδωεϩδοΫ͕͜͜ʹೖΔɻ ྫʣ์ૹIDΛݩʹ์ૹใΛऔಘ͢ΔɺTwitter࿈ܞใΛݩʹαʔϏεͷೝূΛߦ͏ͳͲɻ
CleanArchitectureͱʁ Interface AdaptersʢControllers/Presenters/Gatewaysʣ UIDBͳͲͷ֎෦ػؔͱɺϢʔεέʔεΤϯςΟςΟͳͲͷυϝΠϯʢαʔϏεͷࠜװʣͱͷؒͷڮ͠ͷͨΊͷɺ σʔλมΛߦ͏Adapter܈ɻ͜ͷUIDBʹؔ͢ΔใΛ͍ͬͯΔ͕ɺEntity UseCaseΒͳ͍ɻ
CleanArchitectureͱʁ Frameworks & DriversʢWeb / UI / DB …ʣ ͜ͷઃܭʹ͓͚Δ࠷֎ɻDBUIϑϨʔϜϫʔΫͳͲ͕͜͜ʹଐ͢Δɻ
FY 42-ωοτϫʔΫͷίʔυɺ6*ͷඳըͳͲ
CleanArchitectureͱʁ ґଘؔͷϧʔϧ ԁͷ֎ଆͷ͕ଆͷʹґଘ͢Δɻʢଆͷ֎ଆͷͷ͜ͱΛΒͳ͍ʣ ଆͷͷ͕֎ଆͷͷΛར༻͢Δͱ͖ɺΠϯλʔϑΣʔεΛఆٛͯ͠ʢ͞ΒʹDIͱΈ߹ΘͤΔ͜ͱʹΑΓʣɺૄͳؔ Λ่͞ͳ͍ɻʢϢʔεέʔε͕DBΛѻ͏߹RepositoryΠϯλʔϑΣʔεΛఆٛ͢Δʣ
࣍ ❖ CleanArchitectureͱʁ ❖ CleanArchitectureʹج͍ͮͨAndroid։ൃ ❖ ;Γ͔͑Γ
CleanArchitectureʹج͍ͮͨAndroid։ൃ
Activity/Fragment Viewͱͯ͠ͷׂ→ViewModelͷใΛը໘ʹදࣔ ίϯτϩʔϥͱͯ͠ͷׂ→PresenterͷϦΫΤετ ViewModel ֤ը໘ͷঢ়ଶɻ Presenter ֤ը໘ݻ༗ͷϩδοΫɻ UseCase σʔλͷऔಘߋ৽ͳͲͷϏδωεϩδοΫ Entity
αʔϏε্ͷ֓೦Λͦͷ··දݱͨ͠Ϋϥε܈ɻ ϢʔβʔใɺνϟϯωϧใͳͲɻ Repository ӬଓԽσʔλͷग़͠ೖΕɻ "1*%#ͷΞΫηεΛϥοϓ͢Δɻ API DB APIϩʔΧϧDB͔Βͷσʔλͷऔಘɻ CleanArchitectureʹج͍ͮͨAndroid։ൃ
CleanArchitectureʹج͍ͮͨAndroid։ൃ Activity/Fragment Viewͱͯ͠ͷׂ→ViewModelͷใΛը໘ʹදࣔ ίϯτϩʔϥͱͯ͠ͷׂ→PresenterͷϦΫΤετ ViewModel ֤ը໘ͷঢ়ଶɻ Presenter ֤ը໘ݻ༗ͷϩδοΫɻ UseCase σʔλͷऔಘߋ৽ͳͲͷϏδωεϩδοΫ
Entity αʔϏε্ͷ֓೦Λͦͷ··දݱͨ͠Ϋϥε܈ɻ ϢʔβʔใɺνϟϯωϧใͳͲɻ Repository ӬଓԽσʔλͷग़͠ೖΕɻ "1*%#ͷΞΫηεΛϥοϓ͢Δɻ API DB APIϩʔΧϧDB͔Βͷσʔλͷऔಘɻ
֎෦ͷӬଓԽػߏ͔Βσʔλ͕ฦ͍ͬͯ͘ྲྀΕɺ RxJavaΛར༻ͯ͠ObservableͷܗͰฦ͢ɻʢίʔυ ͕γϯϓϧʹͳΔͷͰʣ CleanArchitectureʹج͍ͮͨAndroid։ൃ
ԁͷଆ͔Β֎ଆʹ͔͏ՕॴInterfaceΛఆٛ͠ ͯɺ֎ଆͷΫϥε͜ΕΛimplements͢Δɻ ͜ΕʹΑΓɺଆͷΫϥε͕֎ଆͷΫϥεʹґଘ͠ͳ ͍Α͏ʹ͢ΔɻʢDIʹDagger2Λར༻ʣ CleanArchitectureʹج͍ͮͨAndroid։ൃ
| |- 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։ൃ
CleanArchitectureʹج͍ͮͨAndroid։ൃ ۩ମతͳίʔυͷհ αϯϓϧɿϩάΠϯϢʔβʔใΛදࣔ͢Δը໘
| |- core | |- user | |- repository //
Repository & Dao /Api | | |- UserRepositoryImpl | | |- UserApi | | |- UserDao | | | |- usecase // UseCase | | |- GetLoginUser | | | |- User // Entity | CleanArchitectureʹج͍ͮͨAndroid։ൃ
Entity CleanArchitectureʹج͍ͮͨAndroid։ൃ Entityͷׂ ɾαʔϏεͷࠜװͱͳΔ֓೦ͷఆٛΛߦ͏
UseCase CleanArchitectureʹج͍ͮͨAndroid։ൃ UseCaseͷׂ ɾΞϓϦέʔγϣϯͷϏδωεϩδοΫ ɾThreadͷઃఆɻ࣮ߦผεϨουɺ݁ՌΛฦ͢ͷϝΠϯεϨουɻʢ࣮ࡍͷ։ൃͰجఈΫϥεͰߦ͍ͬͯΔʣ ɾϦϙδτϦΛར༻ͨ͠ॲཧɻෳϦϙδτϦΛར༻͢Δ͜ͱ͋Δɻ ɹʮϩάΠϯϢʔβʔΛऔಘ͔ͯ͠ΒϢʔβʔͷνϟϯωϧใΛऔಘ͢ΔʯͳͲ
UseCase CleanArchitectureʹج͍ͮͨAndroid։ൃ UseCaseͷׂ ɾΞϓϦέʔγϣϯͷϏδωεϩδοΫ ɾThreadͷઃఆɻ࣮ߦผεϨουɺ݁ՌΛฦ͢ͷϝΠϯεϨουɻʢجఈΫϥεͰߦ͍ͬͯΔɻίʔυׂѪʣ ɾϦϙδτϦΛར༻ͨ͠ॲཧɻෳϦϙδτϦΛར༻͢Δ͜ͱ͋Δɻ ɹʮϩάΠϯϢʔβʔΛऔಘ͔ͯ͠ΒϢʔβʔͷνϟϯωϧใΛऔಘ͢ΔʯͳͲ
Repository CleanArchitectureʹج͍ͮͨAndroid։ൃ Repositoryͷׂ ɾӬଓԽػߏʹର͢ΔγϯϓϧͳΠϯλʔϑΣʔεΛఏڙ ɾ۩ମతͳDBAPIͷ࣮ผΫϥεʹఆٛ͠ɺͦΕΛར༻͢Δ͚ͩɻʢDao/ApiͷίʔυׂѪʣ
| |- mobile | | | |- ui | |-
user // Activity/Fragment&Presenter&ViewModel | |- UserActivity | |- UserComponent | |- UserPresenter | |- UserView | |- UserViewModel CleanArchitectureʹج͍ͮͨAndroid։ൃ
Presenter CleanArchitectureʹج͍ͮͨAndroid։ൃ Presenterͷׂ ɾUIϩδοΫͷ୲͍खɻUseCaseΛ༻͍ͯɺը໘ͷඳըʹඞཁͳॲཧΛߦ͏ɻ ɾUseCaseͷ݁ՌΛViewʹ͑Δͱ͖ɺViewΠϯλʔϑΣʔεΛఆٛͯ͜͠ΕΛܦ༝͢Δ PresenterͷجఈΫϥεͰߦ͏ॲཧʢίʔυׂѪʣ ɾڞ௨ͷΤϥʔϋϯυϦϯάʢex. ڧ੍ΞοϓσʔτͷΤϥʔίʔυ͕͖ͨΒμΠΞϩάදࣔʣ ɾSubscriptionͷཧʢActivity.onDestroyͰ࣮ߦதͷॲཧΛഁغ͢Δʣ
ViewModel CleanArchitectureʹج͍ͮͨAndroid։ൃ ViewModelͷׂ ɾը໘ʹؔ͢Δঢ়ଶΛ͜͜ʹఆٛ͠ɺมߋΛActivity/Fragmentʹ௨͢Δ ɾandroid.databinding.Observableʓʓ ͕ศར
Activity/Fragment CleanArchitectureʹج͍ͮͨAndroid։ൃ Activity/Fragmentͷׂ ɾViewModelͷใΛViewʹඳը͢Δ ɾPresenterʹॲཧΛϦΫΤετ͢Δ ʢϥΠϑαΠΫϧɺΫϦοΫΠϕϯτɺetc..ʣ
| |- 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είʔϓͰఆٛͰ͖Δ
࣍ ❖ CleanArchitectureͱʁ ❖ CleanArchitectureʹج͍ͮͨAndroid։ൃ ❖ ;Γ͔͑Γ
;Γ͔͑Γ Α͔ͬͨ͜ͱ ɾ͖Ε͍ʹ͔͚Δ&͋Δఔ͓ܾ·Γͷίʔυʹͳͬͯ͘ΔͷͰɺ ɹਂ͘ߟ͑ͣʹॻ͚Δ͠ϨϏϡʔ͍͢͠ɻ ɾςετॻ͖͍͢ʢҰ൪֎ଆҎ֎୯७ͳjavaͷςετίʔυ͕ॻ͚Δʣ ɾείʔϓΛݶఆͯ͠ίʔυΛΊΔͷ͕خ͍͠ ΘΔ͔ͬͨ͜ͱɺେมͩͬͨ͜ͱ ɾ؆୯ͳػೳՃͰίʔυྔଟ͘ͳΔ ɾνʔϜͰͷڞ༗ʢGithubͷwikiΛར༻ɻ͋ͱϨϏϡʔ͠ͳ͕Βʣ
CleanArchitectureϕʔεͰAndroidΞϓϦͭͬͨ͘ ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ