I'm facing an issue where I have a Model which I want to implement a GUI for. As I'm exploring MVVM and WPF I will of course use a View Model between the View and Model. I will also have a need to add coordinates to some model classes that represents objects that will be drag able in the GUI. At this time, this is the only addition to these particular model classes that I need. At least at this moment. At the same time almost all, if not all, information contained in the model objects is of interest to the view.
The most important model classes are:
- Table
- Columns
Dependencies
Tables know of its columns.
- Columns know which Table they belongs to.
- Columns know 1..* Dependencies
- Dependencies know 1..* column it represents a dependency to.
It would of course be possible to modify how these objects know of each other, if needed.
The real question here though, is; How do I make the model classes available to the View, when at the same time adding coordinates to Tables, Columns and Dependencies?
One way might be to create something like this:
public class TableViewModel
{
public Model.Table ModelTable { get; private set; }
public List<ColumnViewModel> Columns { get; set; }
public float X { get; set; }
public float Y { get; set; }
}
Is this a preferred way to forward an "extended" Model object to the View or are there patterns specifically engineered for this task?
Would regular inheritance between the objects in Model and View Model work? I'm not sure though, I like the coupling that would cause.
Or should I create View Model classes that are tailored to fit the View and then map properties from the Model object to the View Model object? This would completely remove the coupling between View and Model, but create two objects in memory, and in this case these might be very big models. Will the garbage collector drop the model objects since there will be no more references to them after they have been mapped to the view model?