https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
android-architecture
  • u

    ursus

    02/18/2022, 1:27 PM
    I have a design question which comes up often for me I have 2 apps which share a viewmodel which emits a list of 3 types which is a sealed class Now business requirement came where app B wants to add 4th type What to do? Do you make the hierqrchy not sealed? Do you remap into new hierarchy? Do you copy paste the original list generation logic to avoid mapping?
    l
    c
    • 3
    • 234
  • v

    vesp

    02/18/2022, 5:14 PM
    Is there a repo that you folk would suggest that make a strong use case for using MVI with Kotlin Coroutines? I'm trying to wrap my head around it but some sample code to look over would make it click.
    t
    • 2
    • 4
  • u

    _shtomar

    03/03/2022, 3:27 AM
    What do you guys tends to use Flow or livedata?
    g
    l
    +2
    • 5
    • 9
  • u

    ursus

    03/14/2022, 12:39 AM
    Noob question, is there a main thread per app? Or a single one for the whole OS ui? i.e. do I lag the whole phone if I do blocking stuff on main thread in Service (running the my app ui is in background)?
    c
    s
    t
    • 4
    • 9
  • v

    Vishnu Haridas

    03/19/2022, 7:50 PM
    A question, or more of a request for comments / opinion / recommendations based on the new architecture. Question: In a repository, will you return a value from a read operation call, or will your return nothing and emit the results via an exposed flow? Here's an example (pseudo-code) of a read operation
    getNews()
    class NewsRepository( localSource, remoteSource ){
    
       val flow: Flow< Resource<NewsItem> > = // exposes the data, updates, and statuses
    
    
       // Will you return a Resource<> here...
       suspend fun getNews(): Resource<NewsItem> {
    .
          if(success) return Resource.Success(list)
          else return Resource.Error(exception)
    
       }
    
       // ...Or return nothing and just emit the result?
       suspend fun getNews(){
          
          if(success) _flowData.emit( Resource.Success(list) )
          else _flowData.emit( Resource.Error(exception) )
    
       }
    
    }
    There can be other functions in the repository that will update the Flow and return nothing, for example:
    suspend fun removeItem( newsId ){
    
         // Remove item from the local copy
         list.remove(newsId)
    
         // Notify listeners
        _flowData.emit( Result.success( list ) )
    
    }
    So my feeling is that I should make all the CRUD functions in the repository to return nothing but just update the Flow to avoid confusion. Comments?
    k
    a
    +3
    • 6
    • 14
  • v

    Vikas Singh

    03/28/2022, 12:05 PM
    I have a use case where i need to register a user, The registration process includes 2 steps 1. Upload 2. Status check Status check is done on the basis of an id which is generated in repository Should I send the response of upload to Usecase and then let use case take decision to call status Api ?. Or directly call the status api from repository as i already have the id ?
    a
    c
    • 3
    • 6
  • n

    Nicolai

    04/01/2022, 2:59 PM
    Hi 👋 , Perhaps one of you can be of assistance to me. In my ViewModel I would like to be able to query my local database with LiveData and observe it. For each page in the app I would need to change the query. This works just fine with:
    val observableActionsFilteredByPageId = Transformations.switchMap(filterPageId)
    However, now I want to filter that data with different values. Meaning that for each page I would need multiple lists filtered by some other parameter... Something like this:
    val contentView = observableActionsFilteredByPageId.map { actions ->
        actions?.filter { it.actionType == "action_contentView" }
    }
    
    val notifications = observableActionsFilteredByPageId.map { actions ->
        actions?.filter { it.actionType == "action_notification" }
    }
    Would this be a proper way to do it or am I using the APIs wrongly? Thanks for your time!
    a
    • 2
    • 1
  • a

    Ali

    04/02/2022, 2:36 PM
    Hey Guys, I would like to know your opinion and suggestions on how you handle errors(Network, API, Database, Parsing etc) passing from the data layer to the UI layer in your android clean architecture app?
    a
    m
    c
    • 4
    • 8
  • e

    Erik

    04/07/2022, 12:38 PM
    Hi Guys! I would like to know about Apps Migration from a Monolith application to same application but using a Modular Architecture. I have some doubts about these points below: 1. Migrate to the Modular Architecture is more feasible to use a Single Activity patterns and inside each module have one or more Fragments with each responsibility related to the module. 2. If I have modular architecture to navigate between Main Activity to the others modules I can use Navigation component (from Jetpack) in a easy way OR I'll need to combine this approach with Navigation + Deeplinks. I really appreciate any information about it, references or best practices :) Thanks
    s
    • 2
    • 2
  • v

    Vishnu Haridas

    04/19/2022, 5:34 PM
    This is a question on UseCase in the Domain Layer. The article discourages using
    Util
    classes and putting shared logic in the domain layer as UseCases. If that's the case, can I use
    object
    s as a UseCase, for example:
    // domain/GetTimeAgoUseCase.kt
    
    object GetTimeAgoUseCase {
       operator fun invoke(time: Long){
         // return "a week"
       }
    }
    ..and use it in my UI layer like this:
    class HomeViewModel: ViewModel(){
       
       fun getTime(): String = GetTimeAgoUseCase(item.timestamp)
    
    }
    ..or..
    @Composable
    fun ListItem(item){
       Text("Posted ${ GetTimeAgoUseCase(item.timestamp) } ago")
    }
    c
    • 2
    • 3
  • s

    Slackbot

    05/05/2022, 4:04 PM
    This message was deleted.
    :blob-thinking-upside-down: 2
    j
    r
    c
    • 4
    • 3
  • a

    Aaron Waller

    05/09/2022, 5:39 PM
    What are the other use cases of the repository class? I know its used for getting Data from the server or cache but what else is the repository used for? I’m using the MVVM pattern and wonder where to put I/O operations like saving and writing a file. I also have a coin system in my app and I need to access that coin int from every screen in my app (settings, profile, home etc), is the Repository a good place to put it?
    a
    k
    +3
    • 6
    • 5
  • t

    Tariyel Islami

    05/14/2022, 10:39 PM
    Hi guys, I have a card. When the Update button is pressed, the name of the card changes with the value entered in the Textfield. I was wondering I need to send viewmodel to this card as a parametr or just send my onClick method? Or how should I send a lambda to the button in the card so that it receives the textfield value in the card?
    t
    • 2
    • 1
  • v

    Vikas Singh

    05/20/2022, 4:56 PM
    Can we make a domain layer as an android library to get the benefit of some android components such as parcelable ?
    o
    a
    • 3
    • 3
  • u

    _shtomar

    05/23/2022, 7:36 PM
    Hi all, if we add ndk.filters with only arm support, will it restrict the apk to be installed only on arm based devices?
    :not-kotlin: 1
    e
    l
    • 3
    • 2
  • k

    K Merle

    05/26/2022, 9:34 AM
    In multi-modularized project, we have module Feature1 and module Feature2. If Feature1 needs an information from Feature2, what should I expose from Feature2, a data module or domain module?
    j
    a
    t
    • 4
    • 3
  • l

    Lokik Soni

    06/17/2022, 6:10 PM
    Hi I am using clean architecture to develop app but I am confusing in sending states from ViewModel to Compose Screen i.e State to show Sanckbar and State to navigate. I am getting confuse in handling that state in Compose. Please see the code below:
    c
    • 2
    • 3
  • m

    Mark Lurie

    06/21/2022, 6:47 AM
    Hey all, I’m working on a large scale project which is written in a legacy arch (started in 2019, yet written in MVC & Dagger). I was given the opportunity to research for a while & decide on an arch change. I’d like to ask you for advices and best practices on refactoring my project. I’m studying the differences between MVVM & MVI and the new DI frameworks (Koin/Hilt?) Thank you!
    c
    c
    • 3
    • 3
  • v

    Vikas Singh

    06/23/2022, 8:36 AM
    Where should one handle the exceptions thrown from the external SDK ? Should it be handled in data sources or repo ?
    c
    r
    • 3
    • 3
  • f

    fuad

    06/25/2022, 12:38 AM
    Room / Modules / architecture question... Typically with initializing Room you need a reference to Application Context. If you're building a library / SDK that needs to write to a Room database, what's the proper way to handle Room? Does the library own it's own Room instance? Do you want to create a singleton within your library to then reference Room from the library and to provide a handle to code using the library to read from the database? I found such suggestions in this SO post : https://stackoverflow.com/questions/62190220/room-database-setup-in-android-library-module but not really sure if this is actually the best or even a recommended approach.
  • l

    Lokik Soni

    06/25/2022, 1:34 PM
    Hi all I am using Clean Architecture (Data, Domain, Presentation layers) to build app but I am confused in which layer should put BroadcastReceiver. I am using BroadcastReceiver for listening Battery changes like whether the charger is connected or not to show In UI etc. According to this https://stackoverflow.com/questions/59576331/android-specific-code-in-clean-architecture I should put BroadcastReceiver in Data layer because it is giving me data. But I think it is android component it should be in presentation layer. Please answer this . Thanks
    v
    v
    c
    • 4
    • 18
  • t

    takahirom

    07/10/2022, 10:36 AM
    I really appreciate the Now in Android app for giving me a lot of insight. I am reading the Modularization learning journey in the Now In Android app. I found this sentence.
    A feature module should have no dependencies on other feature modules.
    I was wondering what happens when a feature nests more than once. For example, if there is an "article screen" that has a "your article tab" and "daily article tab" in it, I thought that the feature module would want to depend on the feature module. In such a case, does nowinandroid assume that all tabs are implemented in the core module? If it is a simple screen, you can put it in the article feature module, but assume it is a complex and large function.
    Layout structure
    screen -> "article screen" -> "daily article tab"
    module structure
    app -> feature-article(contains "article screen") -> core-dailyarticle(contains "daily article tab")
                                                      -> core-yourarticle(contains "your article tab")
    As I write this message, I am beginning to think that this is not a problem because it works fine. https://github.com/android/nowinandroid/blob/main/docs/ModularizationLearningJourney.md#types-of-modules-in-now-in-android
    k
    a
    +2
    • 5
    • 49
  • v

    Vikas Singh

    07/26/2022, 9:31 AM
    Should we have a repo layer if in some cases it only acts as an interactor between ViewModel and data sources ?
    l
    • 2
    • 1
  • l

    Lilly

    07/28/2022, 8:52 AM
    I have noticed a problem with dependency injection and *multi-module project*s. I have a clean-like architecture using Koin as DI library, but since my android application module is responsible for creating the DI graph, it is forced to know all other modules to grab its "koin modules". To overcome this my only idea is to create a new module called, e.g. di that knows all other modules and defines the "koin modules" so the android application module just need to know the di module. But is this approach common in practice?
    w
    t
    • 3
    • 13
  • v

    Vikas Singh

    08/05/2022, 6:47 AM
    A concern related to ddd - have data to decrypt before passing it to the domain, which layer should decrypt the data ?
    g
    • 2
    • 2
  • l

    Lukasz Kalnik

    08/05/2022, 12:56 PM
    I have a Compose
    ModalBottomSheetLayout
    where the contents is the main screen with a list of items, and the
    sheetContent
    are item details (with different settings). As the item details are quite complex, and don't influence the main screen, I would like to have them in a separate ViewModel. How can I pass the
    itemId
    from the
    MainScreenViewModel
    to the
    ItemDetailsViewModel
    . I don't really fancy creating a shared ViewModel just to pass one value (which is anyway only temporary, as the
    ItemDetailsViewModel
    will store
    itemId
    as well to get the item data).
    k
    a
    • 3
    • 4
  • a

    aungbophyoe

    08/24/2022, 4:40 PM
    Hi anyone , I have interview question about android development. What is your usual stack of components and libraries for an android app’s architecture? Please answer me, if you know that. thanks you.
  • l

    Lukasz Kalnik

    08/25/2022, 4:54 PM
    Is there a best practice about naming the different components on different layers of clean architecture? We currently use:
    data
    layer: •
    ...Api
    suffix for the Retrofit interface definitions (e.g.
    MoviesApi
    ) •
    ...Repository
    suffix for the class that abstracts away the
    Api
    .
    domain
    layer: •
    ...UseCase
    for commonly used, well, use cases, they usually depend on
    Repository
    (although often we skip this layer altogether)
    presentation
    layer: • obviously
    ...ViewModel
    here. I'm asking because I have a
    ViewModel
    which grew really large, so I would like to split it in multiple viewmodels. However they all share common view data to some degree, so have to depend on a single source of truth in the presentation layer. And I was wondering how to call such single source of truth in the presentation layer.
    g
    r
    • 3
    • 8
  • a

    Asad Mukhtar

    08/27/2022, 4:20 PM
    Hi, everyone i`m working on product at my company i have to write the architecture which is good for scalability and maintainability + testable point of good, can anyone recommend me any good architectured based repo for Android?
    g
    • 2
    • 3
  • y

    Yasser AKBBACH

    08/29/2022, 12:11 PM
    Hi all, I have a question, if
    use cases
    in
    clean architecture
    with Android are just calling
    repositories
    , why should we bother creating them? why not injecting
    repositories
    in
    viewmodels
    like we used to do?!
    j
    k
    +6
    • 9
    • 24
Powered by Linen
Title
y

Yasser AKBBACH

08/29/2022, 12:11 PM
Hi all, I have a question, if
use cases
in
clean architecture
with Android are just calling
repositories
, why should we bother creating them? why not injecting
repositories
in
viewmodels
like we used to do?!
j

Javier

08/29/2022, 12:15 PM
Personally I don't like repositories and I only use use cases
k

K Merle

08/29/2022, 12:36 PM
If your "usecase" is simple, you can have one or the other, but if logic is complex, having repository as single place to search for feature datasource API's and usecase as place where domain logic is done is a good separation imo.
y

Yasser AKBBACH

08/29/2022, 12:39 PM
can u give me an example of a complex use case (in :android:)?
k

K Merle

08/29/2022, 12:41 PM
I would consider it if it's talking more than 1 API that is in a lower level, this includes also if it's consuming 2 API's from same repository. Example, user changed some field, and we need to store data locally and send network request.
y

Yasser AKBBACH

08/29/2022, 12:43 PM
I see, but don't you think that in most cases we only go with passing the
input
and caring about
output
and most of the work is being done in the
repos
🤔 ?
k

K Merle

08/29/2022, 12:44 PM
You can do it in repository, but for me, repository is the place where I put all my datasource API's, so it's a place of gathering the datasource API's, and not some high-level place that usecases were supposed to be.
y

Yasser AKBBACH

08/29/2022, 12:45 PM
Yeah as the name says it's a
repository
Thanks 🙏
j

Javier

08/29/2022, 12:47 PM
curiously, clean arch says nothing about repositories
k

K Merle

08/29/2022, 12:49 PM
I wonder if Gateways could be considered a Repository.
https://martinfowler.com/eaaCatalog/gateway.html
https://martinfowler.com/eaaCatalog/repository.html
j

Javier

08/29/2022, 12:54 PM
I think it is adding complexity which is going to be useless a lot of times, overall in Android applications, like creating mappers as objects that are injected lately instead of simple functions.
y

Yasser AKBBACH

08/29/2022, 12:55 PM
You're speaking my suffering man 😂
j

Javier

08/29/2022, 12:56 PM
almost all android application just draw fetching from API and adding offline support, without a really complex logic. You can inject all of those objects in the use case implementation and and don't have a huge function
meanwhile using both, repositories and use cases, you will get tons of anemic use cases
k

K Merle

08/29/2022, 12:59 PM
It should certainly be thought before if it makes sense.
c

curioustechizen

08/29/2022, 2:58 PM
Anemic use cases is a pain; but combining use cases and repositories is not the right solution according to me; and it is a layering violation. In the architectures that I've worked with: • UseCase resides in the domain layer • Respository interface resides in domain layer (so use cases have access to repository interfaces) • UseCases only handle the business logic. Specifically, UseCases do not know about where or how your data is stored. They definitely do not know about your backend URL or JSON formats. • Repository implementations reside in data layer. These repository implementations are the ones responsible for API calls/database calls/JSON parsing etc. A more viable alternative to avoid one-liner usecases is to inject repository interfaces directly into ViewModels where it makes sense, and inject UseCases in ViewModels only if the UseCase is more than a one-liner. However in practice I've found that it is makes things more predictable to always inject UseCases in ViewModels and never repositories (even if those usecases are likely to start off as one-liners). This is because many times a UseCase might start as a one-liner but then evolve to something more. As a concrete example in one project we introduced in-memory caching for some data; and then a bunch of UseCases which were one-liners turned into UseCases which had logic: First check the cache, if it is there return it; if not fetch it and store into cache before returning.
j

Jan Starczewski

08/30/2022, 7:21 AM
In my opinion just keep both in mind. Analyze the case you are implementing, when it is simple and needed in one place, there sometimes is no need to add an extra UseCase boilerplate. When code needed to use data from repository is getting complicated (business logics grows) and there is a need to use them in many places (depending on the rules in the project, for example: one, two, refactor), just refactor the code to UseCase to encapsulate shared logic.
f

Francesc

08/31/2022, 2:42 AM
A thing to keep in mind is that the presentation layer should not depend on the data layer. With use cases changes to the data layer are isolated to your use cases so that these changes do not leak to the presentation layer, forcing you to do a major refactor in your presentation layer if you make changes at the data layer. Data types should also not leak to the presentation layer, if you change backend technologies that should be transparent to the presentation layer.
k

K Merle

08/31/2022, 7:28 AM
Here is an interesting usecase, where you might see how big usecase can get. https://kotlinlang.slack.com/archives/C0B8M7BUY/p1661928688133889
j

Javier

08/31/2022, 9:56 AM
You can have private function in an use case to allow to understand it.
class SomeUseCaseImpl : SomeUseCase {
    operator fun invoke(id: Id): Flow<Some> {
      val someDto = fetch()
      someDto.saveInDatabase()
      return database.getSomeAsFlow()
    }

   // do network request 
   private fun fetch()

   // map to entity and save
   fun SomeDto.saveInDatabase()

   …
}
a

Arun Joseph

09/02/2022, 1:37 PM
The approach suggested by https://betterprogramming.pub/how-to-avoid-use-cases-boilerplate-in-android-d0c9aa27ef27 seems to reduce the
UseCase
boilerplate while maintaining layering.
p

Pablichjenkov

10/07/2022, 5:44 AM
Test-ability mainly the reason.
d

Davide Giuseppe Farella

10/08/2022, 11:28 AM
The reason is simple, if you inject the repository instead, you add to your VM another reason to change ( remember that a class should have a single reason to change ). For example if before saving a user, you will need to check if the user is not restricted, you will need to change your VM, which is wrong. Additionally, you would need to track down wherever you're saving the user and apply the change
View count: 106