If you think of it as an abstraction, let's say you need to build a screen to display a list of Employees and make a Selection, Search or Filter. Then we break it up in components. You will require:
- An
Employee
class (Model) - An
EmployeeManagementViewModel
to prepare and present your list of Employees and manage state changes for your View (e.g. can contain aSelectedEmployee
, Filter Search text, etc) to be used by yourEmployeeManagementView
- A list of Employees (Which will live in your
EmployeeManagementViewModel
)
Most likely you will already have an Employee
class. If that's the case then you just need to expose that model in your EmployeeManagementViewModel
as an ObservableCollection
of Employees.
In case you don't already have an Employee class you may decide to create an EmployeeViewModel
and add your Employee
properties there like FirstName
, LastName
, etc.
Technically this will work but conceptually it bothers me because an EmployeeViewModel
is not an Employee (it contains an employee). If you're abstracting reality then, the blueprint of an Employee should not include properties or methods to be used by a View. To me Employee should be a POCO which could implement INotifyPropertyChanged
and nothing more than that. You're separating View state from the Model itself. Having an Employee POCO makes it easier to UnitTest, create mock employees, map it to a database table through an ORM, etc.
As the name implies the ViewModel is the model for your View and the Model is the model for your business domain
Anyway that's how I see it. When I started doing MVVM work I had that same question but over the years seems like it makes sense.