Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Are there any design patterns to compose views within a parent view during runtime? Say we are composing the views in a workflow tab and views in the tabcontrol depend on the country, store type and/or other conditions.

This is a MVP, WPF, PRISM application.

share|improve this question
    
Hmm, why not use DataTemplateSelectors which select the DataTemplates based on the locale or other criteria? –  Falcon Sep 7 '11 at 17:09
1  
Sounds like functional composition to me. –  dietbuddha Sep 8 '11 at 4:33
add comment

2 Answers

The closest design pattern I can think of is decorator pattern. That said, are you nesting views, or enabling/disabling/auto-populating fields based on other selections in the UI, in which case you may want to use the strategy pattern?

share|improve this answer
add comment

Would a some form of Factory suffice?

I'm thinking something along the lines of

    var dynamicView = ViewFactory.CreateView(countryCode, storeType, otherConditions);
    Render(dynamicView);

or

    var countryView = CountryViewFactory.Create(countryCode);
    var storeTypeView = StoreTypeViewFactory.Create(storeType);
    var otherView = OtherViewFactory.Create(otherConditions);
    RenderPartial("CountrySection", countryView);
    RenderPartial("StoreTypeSection", storeTypeView);
    RenderPartial("OtherSection", otherView);
share|improve this answer
    
Chris, we are using Unity for DI else factory would be one my choices too. but i was actually wondering whats the best design pattern that can be followed for this scenario! –  ioWint Sep 16 '11 at 3:56
    
The only other thing I can think off is the Composite pattern (en.wikipedia.org/wiki/Composite_pattern) but they may not be appropriate depending on the structure of the views you have. –  Chris Lee Sep 16 '11 at 18:29
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.