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
android-testing-bootcamp-2
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Yuya Kaido
June 09, 2016
Programming
910
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
android-testing-bootcamp-2
Yuya Kaido
June 09, 2016
More Decks by Yuya Kaido
See All by Yuya Kaido
droidkaigi-2019
yuyakaido
7
4.9k
matching-dev-meetup-1
yuyakaido
1
240
minami-aoyama-night-6
yuyakaido
1
1.3k
eureka-meetup-10
yuyakaido
0
850
droidkaigi-2018
yuyakaido
4
6.2k
navitime-eureka-1
yuyakaido
0
110
droidkaigi-2017
yuyakaido
11
8.3k
retty-tech-cafe-8
yuyakaido
0
200
mti-eureka-tech-beer
yuyakaido
0
500
Other Decks in Programming
See All in Programming
AI時代の仕事技芸論 — ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ
kuranuki
1
620
Spring Security 実践 ─ GraphQL APIで実務に役立つ 認証・認可 を学ぶ
wagyu
0
160
Oxcを導入して開発体験が向上した話
yug1224
4
290
These Five Tricks Can Make Your Apps Greener, Cheaper, & Nicer
hollycummins
0
270
AI時代のUIはどこへ行く?その2!
yusukebe
19
6.7k
技術記事、AIに書かせるか、自分で書くか? 〜それでも私が自分の手で書く理由〜 / #QiitaConference
jnchito
2
1.3k
OSもどきOS
arkw
0
460
Signal Forms: Beyond the Basics @ngBaguette 2026 in Paris
manfredsteyer
PRO
0
230
権限チェックの一貫性を型で守る TypeScript による多層防御
mnch
4
1.1k
代数的データ型って何が嬉しいの? #frontend_phpcon_do
kajitack
8
3.2k
AutonomyとControlのあいだ:Graflowで記述するAIエージェント協調
myui
0
110
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
140
Featured
See All Featured
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.8k
SEO for Brand Visibility & Recognition
aleyda
0
4.6k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.5k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
240
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
23k
The Cult of Friendly URLs
andyhume
79
6.9k
sira's awesome portfolio website redesign presentation
elsirapls
0
270
How to train your dragon (web standard)
notwaldorf
97
6.7k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
A designer walks into a library…
pauljervisheath
211
24k
Visualization
eitanlees
152
17k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
390
Transcript
Advanced Dagger for Android Android Testing Bootcamp #2 yuyakaido
ࣗݾհ • ւ౻༏ʢ͔͍Ͳ͏Ώ͏ʣ • גࣜձࣾΤϨΧ • 1ͷΠϯλʔϯΛܦͯɺ20154݄ʹ৽ଔೖࣾ • ςετ͓͡͞Μ
yuyakaido yuyakaido
גࣜձࣾΤϨΧ • ࣗࣾαʔϏεͷاըɾ։ൃɾӡӦ • ΦϯϥΠϯσʔςΟϯάαʔϏεɿ • Χοϓϧઐ༻ΞϓϦɿ • ࣾһɿ104໊ •
IAC ΤϯδχΞ 51ਓ ඇΤϯδχΞ 53ਓ
࣍ • DIͱ • جૅฤ • Ԡ༻ฤ • ·ͱΊ
DIͱ • DI = Dependency Injection • ຊޠͰɺґଘੑೖ • ґଘੑͱ
ґଘੑ • Կͱ͋ΕɺίʔυΛݟͯΈΔ • GithubRepositoryΫϥε2ͭͷΫϥεʹґଘ • ΫϥεA͕ΫϥεBʹґଘ͍ͯ͠Δ͜ͱ͕ґଘੑ public class
GithubRepository { private GithubClient githubClient = new GithubClient(); private GithubDao githubDao = new GithubDao(); }
ґଘੑ • ґଘੑ͕ϕλॻ͖ͩͱԿ͕Ϛζ͍ͷ͔ • Ϣχοτςετ͕ࠔ • ґଘઌͷΫϥε͕ਖ਼ৗʹಈ͍͍ͯΔඞཁੑ • Կͱ͔ͯ͠ґଘੑΛഉআ͍ͨ͠ •
ͱΓ͋͑ͣηολʔΛఆٛ͢Ε͍͍ͷͰʁ
ґଘੑ • ଟগґଘԼ͕͕ͬͨɺࠜຊղܾʹͳͬͯͳ͍ • Ϣχοτςετ͕ࠔ • ґଘઌͷΫϥε͕ਖ਼ৗʹಈ͍͍ͯΔඞཁੑ public class
GithubRepository { private GithubClient githubClient; private GithubDao githubDao; public void setGithubClient(GithubClient githubClient) { this.githubClient = githubClient; } public void setGithubDao(GithubDao githubDao) { this.githubDao = githubDao; } }
public class GithubRepository { private GithubClient githubClient; private GithubDao githubDao;
public GithubRepository(GithubClient client, GithubDao dao) { this.githubClient = client; this.githubDao = dao; } } public interface GithubClient { /* লུ */ } public interface GithubDao { /* লུ */ } ґଘੑ • Ϣχοτςετ͕ࠔ • GithubClientɺGithubDaoΛϞοΫ͢Ε GithubRepositoryͷϢχοτςετ͕Մೳ • ґଘΫϥε͕ਖ਼ৗʹಈ࡞͍ͯ͠Δඞཁੑ • ͱΓ͋͑ͣϞοΫͯ͠͠·͑ಈ͘
DIͱ • DI = Dependency Injection • ຊޠͰɺґଘੑೖ • DI
= ґଘΛϕλॻ͖Λආ͚ΔͨΊͷΈ
Dagger • ಥવͰ͕͢ɺDagger2ͭ͋Γ·͢ • https://github.com/square/dagger • ΦϦδφϧͬͪ͜ • https://github.com/google/dagger •
square/daggerΛϕʔεʹͯ͠Google͕ख ΛೖΕͨͷ
جૅฤ • Inject • Module • Component • جຊతͳ͍ํ
Inject • @InjectΛॻ͘ͱΠϯελϯε͕ೖ͞ΕΔ public class GithubRepository { private GithubClient
githubClient; private GithubDao githubDao; public GithubRepository(GithubClient client, GithubDao dao) { this.githubClient = client; this.githubDao = dao; } }
Inject • @InjectΛॻ͘ͱΠϯελϯε͕ೖ͞ΕΔ public class GithubRepository { private GithubClient
githubClient; private GithubDao githubDao; @Inject public GithubRepository(GithubClient client, GithubDao dao) { this.githubClient = client; this.githubDao = dao; } }
Module • ੜ͢ΔΠϯελϯεΛఆٛ͢ΔΫϥε @Module public class GithubModule {
@Provides public GithubClient provideGithubClient() { return new GithubClientImpl(); } @Provides public GithubDao provideGithubDao() { return new GithubDaoImpl(); } }
Component • ModuleͱInjectରΫϥεͷؔΛఆٛ @Component(modules = {GithubModule.class}) public interface AppComponent
{ void inject(MainActivity mainActivity); }
جຊతͳ͍ํ • DaggerAppComponentΛॳظԽ public class Genesis extends Application {
private AppComponent appComponent; public static AppComponent getAppComponent(Context context) { Genesis genesis = (Genesis) context.getApplicationContext(); return genesis.appComponent; } @Override public void onCreate() { super.onCreate(); appComponent = DaggerAppComponent.builder().build(); } }
جຊతͳ͍ํ • Inject͢Δ public class MainActivity extends Activity {
@Inject GithubRepository githubRepository; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Genesis.getAppComponent(this).inject(this); } }
Ԡ༻ฤ • Dependencies • Subcomponent
લఏ • ΞϓϦͷنʹൺྫͯ͠ɺModule૿͑Δ • Module͕૿͑ΔͱComponent͕ڊେԽ͍ͯ͘͠
Dependencies Subcomponent ͱ • ΞϓϦͷنʹൺྫͯ͠ɺModule૿͑Δ • Moduleͷཧํ๏ • Dependencies •
Subcomponent
Dependencies • ґଘ͍ͯ͠ΔModuleΛྻڍ @Component(dependencies = {GithubModule.class}) public interface AppComponent
{ void inject(MainActivity mainActivity); }
Dependencies • ґଘ͍ͯ͠ΔModuleΛྻڍ @Component(dependencies = {GithubModule.class}) public interface AppComponent
{ void inject(MainActivity mainActivity); }
Subcomponent • ComponentΛ֊Խ͢Δ @ScreenScope @Subcomponent(modules = {InstagramModule.class}) public interface
InstagramComponent { void inject(InstagramActivity instagramActivity); }
Subcomponent • ComponentΛ֊Խ͢Δ @ScreenScope @Subcomponent(modules = {InstagramModule.class}) public interface
InstagramComponent { void inject(InstagramActivity instagramActivity); }
Dependencies Subcomponent • Dependencies • ґଘ͍ͯ͠ΔModuleΛྻڍ • Subcomponent • ComponentΛ֊Խ
Dependencies Subcomponent ͷҧ͍ • Dependencies • શͯͷModule͕1ͭͷComponentʹॴଐ • Subcomponent •
Componentࣗମ͕֊Խ͞ΕɺͦΕͧΕ ͷComponent͕ModuleΛཧ ͳΔ΄Ͳɺ͔ΒΜ
Dependencies AppComponent FooModule BarModule
Subcomponent AppComponent FooComponent BarComponent
Dependencies Subcomponent • ͲͪΒΛ͏͖͔ • ن͕খ͚͞ΕɺDependencies • ͋ΔఔͷنΛఆ͢ΔͳΒɺSubcomponent • Dependenciesͩͱ1ͭͷComponent͕શͯͷґ
ଘΠϯελϯεΛཧ͢Δ͜ͱʹɺɺ
·ͱΊ • DIͱԿͳͷ͔ • ґଘੑΛϕλॻ͖͠ͳ͍ͨΊͷΈ • Daggerجૅฤ • ModuleͱComponent •
DaggerԠ༻ฤ • DependenciesͱSubcomponent
ࢀߟ • ཁ͢Δʹ DI ͬͯԿͳͷͱ͍͏ • http://nekogata.hatenablog.com/entry/ 2014/02/13/073043 • Android:
Dagger2 - Subcomponent vs. dependencies • http://yuki312.blogspot.jp/2016/02/android-dagger2- subcomponent-vs.html
Thank you :) Credit: NASA Earth Observatory/NOAA NGDC