I have XML files that are representation of a portion of HTML code.
Those XML files also have widget declarations.
Example XML file:
<message id="msg">
<p>
<Widget name="foo" type="SomeComplexWidget" attribute="value">
inner text here, sets another attribute or
inserts another widget to the tree if needed...
</Widget>
</p>
</message>
I have a main Widget class that all of my widgets inherit from.
The question is how would I create it?
Here are my options:
- Create a compile time tool that will parse the XML file and create the necessary code to bind the widgets to the needed objects.
- Advantages:
- No extra run-time overhead induced to the system.
- It's easy to bind setters.
- Disadvantages:
- Adds another step to the build chain.
- Hard to maintain as every widget in the system should be added to the parser.
- Use of macros to bind the widgets.
- Complex code
- Advantages:
- Find a method to register all widgets into a factory automatically.
- Advantages:
- All of the binding is done completely automatically.
- Easier to maintain then option 1 as every new widget will only need to call a WidgetFactory method that registers it.
- Disadvantages:
- No idea how to bind setters without introducing a maintainability nightmare.
- Adds memory and run-time overhead.
- Complex code
- Advantages:
What do you think is better? Can you guys suggest a better solution?