Model inheritance VS implementation


Hi all,

We're currently working on an MVC 7.5 site, that has some 30 different page types. There are 12 particular properties that are randomly used by some of these page types, and not others. Ordinarily if these properties were used by all of the page types we would add them to a base class and use inheritance - in this scenario that wouldn't work because too many of the derived page types would end up with properties they shouldn't have.

An example of the properties I mention can be seen at:

Therefore, the two choices I foresee are:

1) Add the properties to a base class, and then on the derived types that don't need a particular property, add the [Ignore] and [ScaffoldColumn(false)] attributes. This just feels a little bit of a hack.

2) Break the properties down into individual interfaces, and individually implement them on the page types that need them e.g. IHasTitle, IHasSubtitle etc. The AlloyTech MVC site uses this approach.

I'm not particulary sold on either solution, although I have less issues with the later - it at least provides the additional benefit of being able to query types based on whether they implement a particular interface.

I'd be really interested to hear others thoughts on this. Have you had similar challenges, and if so what route did you take?

Thanks in advance


Aug 19, 2014 15:49

Looking through the solution I'm currently working on I could see that I'm using two diffrent baseclasses, have six property interfaces. But I would also throw in blocks with AvailableInEditMode = false into the mix. They can be a good way group and reuse properties between the pagetypes.

So why is the solution going in all directions? I would say that because the project is constantly evolving and we didn't have all the pagetypes with a nice property list like you have here from the start it's a constant issue to decide what way to go. I have added baseclasses  after the start when I found us adding alot of simular pagetypes.


It depends. =)

Aug 19, 2014 16:19

My vote for "local" blocks as Petter suggested too.

Aug 21, 2014 6:17
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.