SgDotNet
Singapore Professional .NET User Group -For Cool Developers

Classify this pattern

Latest post 04-11-2008 8:52 PM by icelava. 5 replies.
  • 12-04-2006 5:45 PM

    Classify this pattern

    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

  • 04-10-2008 9:27 AM In reply to

    Re: Classify this pattern

    It looks more like a factory to me. Maybe you can give out code snippets for us to analyzeStick out tongue
    Filed under:
  • 04-10-2008 10:30 AM In reply to

    Re: Classify this pattern

    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.

    The melody of logic will always play out the truth. ~ Narumi Ayumu, Spiral

  • 04-10-2008 12:18 PM In reply to

    • cruizer
    • Top 50 Contributor
    • Joined on 07-25-2007
    • Singapore
    • Posts 140

    Re: Classify this pattern

    icelava, i think it's more like a strategy pattern. except that it's a UI-level strategy, not a logic-level strategy.
    http://devpinoy.org/blogs/cruizer
  • 04-11-2008 9:03 AM In reply to

    Re: Classify this pattern

    hi icelava, What about a combination of state pattern + factory/strategy patterns(both factories and strategy are suitable)? You said something about different behaviours based on different inputs. 
    Filed under:
  • 04-11-2008 8:52 PM In reply to

    Re: Classify this pattern

    Which is what prompted me to consider it a Strategic Decorator originally :-)

    The melody of logic will always play out the truth. ~ Narumi Ayumu, Spiral

Page 1 of 1 (6 items) | RSS
Copyright SgDotNet 2004-2008
Powered by Community Server (Commercial Edition), by Telligent Systems