Comments (3)
I was wondering about this too. I can remove
fun setPresenter(presenter: T)
from the BaseView and rely on dependency injection to give the view a presenter reference. I'd like to know the rationale for having setPresenter()
instead of nothing or just a val presenter: T
which would be initialized by dagger.
Another thing which seemed redundant is the @Inject
annotation on the presenter's constructor here:
class BrowseBufferoosPresenter @Inject constructor(
val browseView: BrowseBufferoosContract.View,
val getBufferoosUseCase: SingleUseCase<List<Bufferoo>, Void>,
val bufferooMapper: BufferooMapper): BrowseBufferoosContract.Presenter {
We already provide the BrowseBufferoosPresenter
in our BrowseActivityModule
, so removing this annotation doesn't seem to affect anything. I was thinking that these might just seem redundant in the example app and have some purpose in a larger scale application though. Any insight would be appreciated.
from android-clean-architecture-boilerplate.
setPresenter
function is indeed redundant. There are different ways to associate Presenter and View, so maybe it stayed there by mistake.
BaseView is nice to have for a clear hierarchy, even if it doesn't contain anything. And maybe it will contain some other base functions depending on your requirements.
from android-clean-architecture-boilerplate.
@DevKate Regarding @Inject
annotation – in the current setting it is also redundant.
But what I like to do is to use it and instead remove the corresponding @Provides
function.
There are several reasons for that:
@Provides
function should be static and in Kotlin it's cumbersome to actually implement this:
@Module
abstract class BrowseActivityModule {
// Note that @Scope annotation is gone now, we should mark the implementation class
// (i.e. BrowseActivity) with it, not the interface
@Binds
abstract fun provideBrowseView(
browseActivity: BrowseActivity
): BrowseBufferoosContract.View
@Module companion object {
@JvmStatic
@PerActivity
@Provides
fun provideBrowsePresenter(
mainView: BrowseBufferoosContract.View,
getBufferoos: GetBufferoos,
mapper: BufferooMapper
): BrowseBufferoosContract.Presenter {
return BrowseBufferoosPresenter(mainView, getBufferoos, mapper)
}
}
}
- If we were to add a new constructor parameter to the Presenter, we would have to duplicate the change in
@Provides
function each time. - With constructor injection we can switch to
@Binds
functions which should be preferred to@Provides
functions.
Now in order to do that in Presenter we need to use concrete Use Case implementation, not the SingleUseCase
interface.
It's hard for me to see the case in which we would need to substitute one Use Case interface with different implementations.
And using val getBufferoosUseCase: GetBufferoos
instead of val getBufferoosUseCase: SingleUseCase<List<Bufferoo>, Void>
seems much less verbose and more clear to me.
But, of course, if for some reason you need to use interfaces, then you have to stick with @Provides
functions.
If not, then let's summarise:
- You get shorter and more comprehensible (IMO) constructor parameter declarations for Presenter.
- You get more concise, more readable and perhaps even slightly more performant
@Module
class implementation:
@Module
abstract class BrowseActivityModule {
@Binds
abstract fun provideBrowseView(
browseActivity: BrowseActivity
): BrowseBufferoosContract.View
@Binds
abstract fun provideBrowsePresenter(
browseBufferoosPresenter: BrowseBufferoosPresenter
) : BrowseBufferoosContract.Presenter
}
from android-clean-architecture-boilerplate.
Related Issues (20)
- How to add a child fragment?
- Wrong comment on `SingleUseCase.kt`#45
- Useless @Inject in `BrowseBufferoosPresenter`
- Invalid import (BuildConfig) in BufferooApplication.kt HOT 1
- AndroidTest mobile-ui, java.lang.NoClassDefFoundError - Android KitKat
- Useless BrowseActivitySubComponent
- Presentation Gradle has wrong rootProject.ext
- Question: What would it be to build a pagination? HOT 3
- Question about some strange classes... HOT 4
- Domain layer and Application layer separation HOT 1
- Domain Layer Mapping HOT 1
- How does BrowseAdapter inject automatically without any @Provide method? HOT 2
- App not retrieving data HOT 1
- How can I fetch the data from cache when fetching data from remote failed? HOT 1
- Where should the data model for sending between activity/fragment stay. HOT 2
- How would package/modularize by feature fall into this? HOT 1
- Will the presentation models always be useless? HOT 2
- Where do WorkManager, JobScheduler Fit? HOT 2
- Refreshing Coroutines,Flow, KMM,Compose
- Is this project able to run?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-clean-architecture-boilerplate.