Note that there are some explanatory texts on larger screens.

plurals
  1. POviewmodel inheritance and duplicate model references
    text
    copied!<p>My question is: How to manage an inheritance chain of viewmodels?</p> <p>My situation:</p> <p>I'm having a standard <strong>ViewModelBase</strong> which only implements the INotifyPropertyChanged interface. </p> <p>Furthermore I have a <strong>BusinessObjectViewModel</strong> which has a Guid, a <strong>PersonBaseViewModel</strong> which has the persons core data, a <strong>CustomerViewModel</strong> with customer related stuff and a <strong>EmployeeViewModel</strong> with employee related stuff. </p> <p>All viewmodels certainly encapsulate a modelobject (Customer, Employee, PersonBase).</p> <ul> <li>BusinessObjectViewModel inherits from ViewModelBase</li> <li>PersonBaseViewModel inherits from BusinessObjectViewModel</li> <li>CustomerViewModel inherits from PersonBaseViewModel</li> <li>EmployeeViewModel inherits from PersonBaseViewModel</li> </ul> <p>The model comes via constructor into the viewmodel.</p> <p>If I use a constructor chain (every viewmodel makes a call to the base constructor) every viewmodel has it's model to return the encapsulated values from the model. </p> <p>But I got to have a Model property in every viewmodel. In the case of CustomerViewModel I would have a reference in <strong>CustomerViewModel</strong>, one in PersonBaseViewModel and one in <strong>BusinessObjectViewModel</strong> for one and the same object. That sounds stupid to me.</p> <p>Or I have to cast every property access in the upper viewmodels.</p> <p>p.s. this is just a small cut-out of my model hierarchy.</p> <p>Thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload