conditional object creation

Started by
10 comments, last by dmatter 10 years, 8 months ago

Hi there,

i'm sorry for not replying until now.

So there are 3 Options i can choose from:

  • a catalog system to map the elements used in the xml to its corresponding entities
  • reflection
  • existing xml marshalling frameworks like JAXB

So i tried out the reflection approach during the weekend and at some point i realized that i am not able to generalize all possible entities due to the fact that a button maybe has different attributes than a label.

A catalog system seems to be a much easier way to handle this. But in my opinion there is another problem:

For every entry in the catalog system, representing a special widget, there must be another dictionary that contains every possible attribut for that special widget. This can grow a lot since more and more widgets are implemented.

In the end i will try out JAXB. As far as i read through some examples its mostly based on annotations and should be working fine.

So thanks to all of you for your advices, it helped me a lot.

JAXB is probably built on top of reflection anyway, all of these solutions are mapped under the reflection name as reflection code stands for code that writes itself.

You can still use relfection in that case except you need to add a initialise/deserialise function on the button that accepts the xml node it is created from. This function then determines which fields of the instance to setup so if the node only has one attribute field it will initialise the other one to a default value. This in response is called data driven development and there are a million ways to solve that as well XML is only one solution.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

Advertisement

JAXB is probably built on top of reflection anyway

Yes it is. It just introspects the typenames, method signatures and public variables along with any JAXB-specific annotations to map the XML tags and attributes to/from method and variables on the object. It's pretty much just what you do if you were rolling your own but comes with extra bells and whistles should you need them.

This topic is closed to new replies.

Advertisement