Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In MVVM, who creates the views, view models, and models? And who connects them together?

Tags:

mvvm

In MVVM,

  1. Who creates the first and subsequent views, view models, and models?

  2. Who displays the views?

  3. And who decides which views and which models connect to which view model?

It feels to me like there is always going to be some code/XML/configuration/etc. -- some "connecting tissue", so to speak -- that doesn't fit into any of the Model, View Model, or Model components.

like image 989
code-ninja-54321 Avatar asked Sep 03 '25 05:09

code-ninja-54321


1 Answers

MVVM is a pattern for decoupling UI from code. It's not for building entire application only with these 3 types of classes (view,viewmodel,model). You can still have factories, bootstrappers, repositories, etc.

  1. First view is created differently depending on framework. For example in Caliburn.Micro first view is created in class Bootstrapper with DisplayViewFor<MainViewModel>
  2. There is usually a build-in class that is responsible for looking into folder with specific name (Views) that extracts Views and matches them with ViewModels.
  3. Views and models are connected by name. You have to follow a certain naming convention: Class1View is connected to Class1ViewModel. Models are usually passed via constructor.

Note that I base my knowledge mostly on how Caliburn.Micro does it, but I suspect that it isn't very different from what other frameworks do.

like image 144
FCin Avatar answered Sep 05 '25 00:09

FCin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!