简体   繁体   中英

MVP Pattern for Android(DI - Interfaces)

Can anybody tell me whats the difference in using Dependency Injection(eg Dagger2) to decouple the view(activity) from its presenter or to use Interfaces which the View(Activity) implements to decouple from presenter?

I'm confused.. When I try to Unit Test the presenter both approaches should work. But why using a tool like dagger when simple interfaces are sufficiant? Hope that smbdy. can help. Thanks

there is not any interfere using both interface and Dagger. Dagger is just for DI (dependecy injection) and is used for providing different layers requirements in MVP.

the view interface must be used always because this is how MVP must be and views are decoupled from presenters by implementing an interface.

you use Dagger to provide things from a specific layer to the other. you can completely put Dagger aside and create a helper class in your view layer which implements some helper interface and send it to the presenters through constructions all over the code but this is kinda messy and thats why they use Dagger.

look at my sample project which i used Dagger: https://gitlab.com/amirziarati/Echarge

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM