Why should ViewModel route actions to Controller when using the MVCVM pattern?
- by Lea Hayes
When reading examples across the Internet (including the MSDN reference) I have found that code examples are all doing the following type of thing:
public class FooViewModel : BaseViewModel {
public FooViewModel(FooController controller) {
Controller = controller;
}
protected FooController Controller { get; private set; }
public void PerformSuperAction() {
// This just routes action to controller...
Controller.SuperAction();
}
...
}
and then for the view:
public class FooView : BaseView {
...
private void OnSuperButtonClicked() {
ViewModel.PerformSuperAction();
}
}
Why do we not just do the following?
public class FooView : BaseView {
...
private void OnSuperButtonClicked() {
ViewModel.Controller.SuperAction();
// or, even just use a shortcut property:
Controller.SuperAction();
}
}