Part Inheritance

Topics: Writing modules
Mar 31, 2011 at 9:53 PM

Hi, i'm working on a Mobile module for Orchard. 

I have a DeviceGroup part that can be assigned themes based on device selection rules. Each DeviceGroupPart can have mobile adaptations assigned to it that can be enabled/disabled, so there are parts such as ThemeSwitcherAdaptation, DocTypeAdaptation, ImageResizerAdaptation which contain their own settings.

What I would love to know, is what is the best way to tie all the adaptation parts to the DeviceGroupPart and have a generic way to get at the adaptations Enabled and Name data, as I don't want to make any assumptions of what adaptations are installed.

I assume the easiest way is just to do a, 

               cfg => cfg

But i'm not sure how to set if the adaptation is Enabled in a generic way.

If I was doing this normally I would start with inheritance and have something like,


WebAppAdaptation : MobileAdaptationPart
As a bit more context, I would like all adaptations to display in a table on the DeviceGroup page with a checkbox to set if enabled and the rest of the adaptation's settings next to it. Haven't even got to how i'm going to group all the adaptations together on the page :)

What is the best way to do this in Orchard?



Mar 31, 2011 at 10:02 PM

It's best to try to forget about inheritance and think in terms of composition instead. Put the commonalities into a common part, and put the specializations in as many separate parts as needed.

Mar 31, 2011 at 10:06 PM

Okay I can see how to do this now and will be able to head down one path instead of being unsure which is the way to go. Thanks!

Also you are way too fast at replying haha, cheers :)