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
2k
CleanArchitecture For Android
CleanArchitectureを参考に、Androidアプリをつくってみたことの紹介
MinoHiroki
January 14, 2017
Tweet
Share
Other Decks in Technology
See All in Technology
LINEスキマニにおけるフロントエンド開発
lycorptech_jp
PRO
0
330
AWS re:Invent 2024で発表された コードを書く開発者向け機能について
maruto
0
190
【re:Invent 2024 アプデ】 Prompt Routing の紹介
champ
0
140
Qiita埋め込み用スライド
naoki_0531
0
860
DevOps視点でAWS re:invent2024の新サービス・アプデを振り返ってみた
oshanqq
0
180
私なりのAIのご紹介 [2024年版]
qt_luigi
1
120
TSKaigi 2024 の登壇から広がったコミュニティ活動について
tsukuha
0
160
Amazon SageMaker Unified Studio(Preview)、Lakehouse と Amazon S3 Tables
ishikawa_satoru
0
150
Snykで始めるセキュリティ担当者とSREと開発者が楽になる脆弱性対応 / Getting started with Snyk Vulnerability Response
yamaguchitk333
2
180
1等無人航空機操縦士一発試験 合格までの道のり ドローンミートアップ@大阪 2024/12/18
excdinc
0
150
AIのコンプラは何故しんどい?
shujisado
1
190
OpenAIの蒸留機能(Model Distillation)を使用して運用中のLLMのコストを削減する取り組み
pharma_x_tech
4
550
Featured
See All Featured
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.9k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
247
1.3M
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
How to Ace a Technical Interview
jacobian
276
23k
Making Projects Easy
brettharned
116
5.9k
It's Worth the Effort
3n
183
28k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
A Philosophy of Restraint
colly
203
16k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
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ΞϓϦͭͬͨ͘ ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ