Is it considered a bad practice to make a custom V...
# android
v
Is it considered a bad practice to make a custom ViewModel and then have your other viewmodels that need it extend it instead of the official one?
not kotlin but kotlin colored 2
a
There is a general guideline saying to favor composition over inheritance.
👍 1
c
Your question is not related to Kotlin, so off-topic in this workspace.
👎 1
p
Is a bad practice yes, inheritance in general doesn't scale well
v
How would you go about injecting one viewmodel into another?
p
The ViewModel pattern itself says there should be only one ViewModel per view. To handle the view state updates and interactions with other parts of the App. If you have the need for inherit a specific common code, or reusing some common ViewModel code. Then you should move that code to a common
UseCase
UseCases are the way ViewModels interact with other parts of the App. A view model "should" only depend on UseCases that resolve everything the VM need.
v
Thank you. The app does not use MVVM architecture, but rather DDD. I guess I will try to move the shared logic to one of the service layer functions
👍 1
p
Yeah that's a good place for common logic too
1