Last year i was involved in a large Windows Forms project that had heavy use of Infragistics' NetAdvantage controls. Some of the complex requirements demanded the flexibility and additional functionality the NetAdvantage controls offered. One of this included the dynamic display of question/answer choices questionaire scripts in an UltraGrid.
What this means is that the first column shows the question, while the second column gave users choices on how to answer the question. The key thing here is different types of questions yielded different types of answer controls: text box, drop-down lists, combo boxes, check boxes, etc. So the program must parse the type of each question and render the appropriate set of controls on its corresponding answer column.
How I went about this is to define a base class that typically puts a TextBox in the Cell it is supposed to handle. Out of that I derive a variety of sub-classes that render a different set of controls accordingly to question type. I shall not go too deep into the rest of the details.
My question is, what type of pattern would you consider this to be?
It is not exactly like a Decorator since that tends to be a passive decoration of controls, and a Strategy tends to be deeper in application/business logic (at least these are what my understanding makes me think of them). This is UI-level polymorphism. Does that somewhat make it a hybrid? "Strategic Decorator" ? :-)
The melody of logic will always play out the truth. ~ Narumi Ayumu, Spiral
There is a factory to instantiate the appropriate/specific class, but that is only part of the overall solution. I am talking about the greater pattern in effect here; the functionality that affects the presentation, behaviour, and logic of the UI. It is hard to post the code in condensed form when there are several class files to illustrate.
As described, each row in the grid is a pair of question/answer. Based on the answerType, the Answer column has to present a set of input controls for the user - text box, radio buttons or drop-down (single choice), check box (multi choice), additional buttons to launch extra dialog box, calendar/dateTime, etc. As you can see is it more than a simple Decorator because there is a significant difference in functionality/logic between the answerTypes. These are not User Controls either; they simply manipulate the UltraGrid's cell differently to achieve the desired effect.
http://devpinoy.org/blogs/cruizer