Generic Builder Pattern

I'm currently working on a project that deserialises XML into objects. The structure is already decided by another source, so I have no influence over that. I've decided to use a builder pattern, where the builder object collects each constructor parameter and uses them to build an object from the parameters.

What I want to do is make a generic version that can build an object using a map of some sort rather than creating a separate builder for each of the numerous objects I need to construct.

My current, prevailing idea is to construct the builder object with a map from element name to a structure containing constructor parameter index and type, then pass those parameters on to the built object's constructor.

I'm not sure if this is a good way to handle this (ie. through the use of reflection), so I'd like anyone's opinion of this idea or some better ways of doing it.

Comments

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion