views:

212

answers:

3

I am writing a section of code that allows "soft" forms, such as a configurable questionnaire or checklist. The header table/class just groups together a bunch of questions, where each question has a "Text" property for the question itself, an "AnswerType" enumeration (string/boolean/StronglyAgree-StronglyDisagree) etc., an order property and whatever other little bells and whistles; you get the picture. And actual instances of the questions being answered can likewise be saved in relation to the question set as opposed to having hard-coded columns.

The details are actually unimportant. My question is: what is this design pattern called? What would be an appropriate name for the tables that are storing the soft-coded questions?

I thought of "SoftForm", which probably comes closest to describing the situation, but I've never heard of such a term before, and I'm sure there's a standard term for this design pattern. What is it?

A: 

It seems like a flavor of Model-View-Controller, as applied to forms. Though the view and controller are probably fused together in your particular example, which is why it is hard to see.

  • Model is the data for the form.
  • View is responsible for visualizing the form data to the user.
  • Controller is responsible for handling the users' answers.
jdmichal
+1  A: 

ISPF called them panels, HTML and XAML calls them forms, Win32 Dialog resources. They all are interpreted, declarative UIs. "declarative UI" is probably the term you want, though what name to use for the DB table is up to you, since you're restricting yourself to a domain specific vocabulary (questionnaires) rather than being general purpose examples.

If you're instead talking about implementing it, then there are several patterns. Some systems effectively interpret the declarative language by parsing in into an object graph (builder pattern). Other systems take the declarative specification, and generate code from that, and run it, either at run-time or when the configuration changes (some JSPs, a couple of systems I've built). You can use standard UI patterns such as MVC within the implementation of either the generative or the object graph approach.

Pete Kirkham
+1  A: 

Sounds like a Builder pattern to me.

chaos
Nope. Builder pattern has a strongly defined interface. This is completely soft-coded, down to the questions and answers.
Shaul
The form isn't the Builder; the code that generates the form representation from the configuration data is. It has a 'strongly defined interface'. The forms aren't an 'interesting pattern' in themselves; the interesting thing about them is that they're dynamically generated to spec.
chaos