Why should ViewModel route actions to Controller when using the MVCVM pattern?
Posted
by
Lea Hayes
on Programmers
See other posts from Programmers
or by Lea Hayes
Published on 2014-08-23T03:27:39Z
Indexed on
2014/08/23
10:34 UTC
Read the original article
Hit count: 332
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();
}
}
© Programmers or respective owner