Is it bad practice to have an inherit from a view model in Asp.net MVC?
<p>I have a situation where I have a bunch of common properties in a view model but have certain cases where I need to extend it.  I created a couple of derrived view models, which I pas into views that expect the derived view Model. (I realize I could use a <a href="https://stackoverflow.com/questions/7222533/polymorphic-model-binding">Polymorphic Binder</a> but I'm happy with just passing in the derived view model for now.</p>

<p>The code looks something like this:</p>

<pre><code>public class CommmonViewModel 
{
     public int? CommonA{ get; set; } 
     public int? CommonB{ get; set; } 
     public int? CommonC{ get; set; } 
}

public class SpecificViewModel1 : CommmonViewModel 
{
     public int? SpecificD{ get; set; }    
}

 public class SpecificViewModel2 : CommmonViewModel 
{
     public int? SpecificE{ get; set; }    
}
</code></pre>

<p>The code reviewer wants me to have three distinct view models and duplicate the code like so:</p>

<pre><code>public class SpecificViewModel1 
{
     public int? CommonA{ get; set; } 
     public int? CommonB{ get; set; } 
     public int? CommonC{ get; set; } 

     public int? SpecificD{ get; set; }
}

public class SpecificViewModel2 
{
     public int? CommonA{ get; set; } 
     public int? CommonB{ get; set; } 
     public int? CommonC{ get; set; } 

     public int? SpecificE{ get; set; }
}
</code></pre>

<p>Now bearing in mind that the real life view models are quite a bit more complex than what I have shown here; I hate that the solution should be to duplicate the code as it feels like a pretty bad violation of DRY to me.</p>

<p>I know there are generally reasons why we would be careful with inheritance and favor composition but in his case inheritance works fine, especially since this part of the system is likely to change in future.</p>

<p>In short, is he right?  is this a case where I should be happy with duplicating code?  What are the advantages\disadvantages of inheriting in this scenario?</p>

<p>Thanks for your thoughts</p>