I had watched Jose Smith video and read some tutorial about MVVM, but I don’t understand how MVVM is loose coupling, i.e View and ViewModel. (still new to MVVM, only tried to built couples project with it.)
In MVP all View, Model, Presenter has interface, so they can be replace or mock for unit testing.
But in MVVM, I don’t see people using interface on the View or ViewModel.
From my understanding, the ViewModel abstracts the data from Model and expose as properties to the View and have the business logic and data manipulation with the model.
So say if I have ViewModel with .SaveData() method and some properties that is used by the View, how do I replace with other ViewModel if they don’t have interface?
Can someone explain to me how is MVVM loose coupling?
MVVM is also supposed to be implemented in terms of interfaces. If you have a class
MyViewModelthen it would also implementIMyViewModelso that it can be mocked for testing. The same goes for the view. So in this specific sense, MVVM is not different from MVP.Other than that, the definition of “loose coupling” is, well… loose, so you ‘d need to be more specific if there are other things you want clarification on.
Note: in MVVM, it would be idiomatic to have a
SaveDataCommandproperty instead of a bareSaveDatamethod (although of course the command is implemented as a method anyway).