I have got a UserViewModel which extends AndroidViewModel class, this class has a MutableLiveData of type User which has informations like user credit inside, this view model also has a editCredit method which sets the new amount of credit a user has(saves on DB and postValue the user property so it can be observed in view)
The other AndroidViewModel class that I've got is CourseViewModel which has properties like courseList or currentCourse. it also has a method called buyCourse which needs to reduce the user credit and add that course to the list of users course. the second property lives in CourseViewModel class and I have no trouble updating that list but for reducing user's credit I need to call editCredit method which lives in other viewModel class.
I know I can use some logics in View Layer and call courseViewModel.buyCourse there and then add an observable method so when it added to user's course list, I can be notified and call userViewModel.editCredit in that layer, but my question is:
Is there any way, a viewModel class can call another ViewModel class's methods?
Update ---
Before I start coupling my view models I had one viewModel which contains more than 400 lines of code, but it could do the job easily but was hard to read (there was not much logics there only calling repository functions) So I tried to change them into smaller view model classes and now I am stuck.
Is there any way, a viewModel class can call another ViewModel class's methods?doesn't seem like a good idea. if one component needs data for it to work, then that data is a dependency and there are known ways of handling dependencies. needing another VM inside your VM is just a way of hiding the fact that you actually need data, which can be passed around