Reputation: 316
I'm trying to use clean architecture but even if I search a lot, it remain a lot of basics question. I understand it's probably a "it depends of your project / needs" but if there is some
I know it's a lot of questions and it's kind of generic / abstract, but I don't think each of them deserve a dedicated topic.
Thanks for your help !
Upvotes: 0
Views: 421
Reputation: 2108
Lots of questions from different domains. I will answer everything from Clean Architecture.
I use Interface/Implementation for repositories. Should i use it for viewmodels, datasources and usecases or is it overkill ? I'm used to do interface for repositories in my domain layer and implementation is the data layer, without interface for datasource (data layer), usecase (domain layer) and viewmodel (presentation layer). Am i right ?
The reason why you use repository interfaces in the domain layer and implementation in the data layer is dependency inversion. You don't want the domain layer to depend on the concrete implementation of the repository in another layer, so you make a UseCase
depend on the interface in the domain
layer and the concrete repository depends on this interface. That's how you inverse.
Boundaries in Clean Architecture are those interfaces you are using. You need them to safely cross boundaries between "layers" (circles).
If you ask if you need to add additional interfaces inside one layer, my answer is - it depends. Depends on the purpose. You don't want to add an interface just to have a meaningless interface. Interfaces are used to abstract something, add common use for several classes, etc. If you see no need for it - you don't need it. Remember that overengineering is the most common mistake in Clean Architecture.
If I have a local source and a remote source (2 datasources), is it the repository or the usecase who have to handle the second source if the first one is down?
According to the official Android doc, the repository handles multiple data sources, and UseCase
knows nothing about them, hence shouldn't handle data-layer-specific problems.
https://developer.android.com/topic/architecture#data-layer
If I want to display the battery level in real time, who have the responsability of polling ? The repository (probably bad for battery if app goes in background) ? Usecases ? ViewModels ?
It seems like a good candidate to infrastructure
or framework
layer. You can find how to implement framework
layer in this article:
https://antonioleiva.com/clean-architecture-android/
It uses location polling as an example. It will answer lots of your questions.
Upvotes: 1