Replies: 5 comments 2 replies
-
From the Clean Architecture POV, |
Beta Was this translation helpful? Give feedback.
-
@lydiasama With this option |
Beta Was this translation helpful? Give feedback.
-
@luongvo We can remove the DataStore dependency from the |
Beta Was this translation helpful? Give feedback.
-
@ryan-conway @lydiasama Do I understand correctly that this discussion has been resolved, as we already merged #389? 🙏 |
Beta Was this translation helpful? Give feedback.
-
Can we close this discussion? @luongvo @ryan-conway What do you think? |
Beta Was this translation helpful? Give feedback.
-
Issue
From this PR: #389, I decided to implement the
AppPreferencesRepositoryImpl
inside ofdata
module.Why?
If we consider a standard Android project, it is common to place SharedPreferences in the app module, as it is often closely tied to the application's lifecycle and functions as a convenient storage location for user preferences and settings. This approach is straightforward and simple, as the SharedPreferences can be accessed directly from the Context of the application.
However, in a more modular or architectural approach, such as MVVM or Clean Architecture, it may be preferable to place the SharedPreferences in the data layer of the application. This approach allows for a clearer separation of concerns, as the data layer is responsible for managing and persisting data, including user preferences. Additionally, this makes it easier to test the data layer and provides a clear API for accessing and modifying SharedPreferences from the rest of the application.
Problem
We need to add
androidx.datastore:datastore-preferences
dependency in bothdata
andapp
modules.👉🏻 data: Uses the dependency for implementing the Sharepreferences handling.
👉🏻 app: Uses the dependency for the
di
module.Solution
We have 2 approaches here with some trade-offs:
Move this
AppPreferencesRepositoryImpl
into theapp
module. We will no longer consider it a resource like when we call the API. And this way, we can get rid of theandroidx.datastore:datastore-preferences
dependency in thedata
module. BTW, when considering the structure betweenAppPreferencesRepositoryImpl
andReposirotyImpl
that we use for calling APIs, it can create another question for other developers about why we don't do the same structure between them.Leave the
AppPreferencesRepositoryImpl
to be in thedata
module and use the same structure withReposirotyImpl
. But this way, we need to add theandroidx.datastore:datastore-preferences
dependency in thedata
module.Who Benefits?
Android developers
What's Next?
Update the #389 after getting the conclusion.
6 votes ·
Beta Was this translation helpful? Give feedback.
All reactions