Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

For my models for a certain section I thought it would be better to have a base class model for both "view" and "edit" models, like so:

public abstract class Setting
{
    [Required]
    public int SettingId { get; set; }

    public string Name { get; set; }

    [Required]
    [MaxLength(255)]
    public string Value { get; set; }
    public string ModifiedBy { get; set; }
    public DateTime ModifiedDt { get; set; }
}

public class ViewSetting : Setting
{
}

public class EditSetting : Setting
{
}

So in my Service or Views I use the appropriate ViewSetting or EditSetting. Right now I don't have anything that would be different - but should I follow a pattern like this to maintain a separation of concerns here? Or should I just stick to using one Setting class? (as an aside, I'm using Entity Frameworks but in my Service layer is where I convert to/from the models for the ORM)

share|improve this question
    
I might consider composition over inheritance in this case. Of course that's probably a preference thing. –  dreza May 15 '13 at 7:05
    
Meaning you would include Setting as an object in both ViewSetting and EditSetting? –  Doctor Oreo May 16 '13 at 0:17
    
Yes that would be one alternative to using the inheritance model –  dreza May 16 '13 at 1:18
    
You mentioned "Right now I don't have anything that would be different". So you don't need it. If you need it, you can always add it later. Try to go with the simplest solution that possibly work. I would simply use a one Setting class as you mentioned. –  Raj May 16 '13 at 8:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.