Seriliasation - OOP issue

Hello.

I have class "A" that needs to creat another class "B".
In one case, class "B" needs to have one attribute/field and in another case two attributes/fields.

I thought to split class "B" into two classes "C" and "D" that one will have one attribute ant the other one two. constructor of "A" will know which to create.

so far - so good.

now I need to serialize the whole thing.
in the output xml, "C" or "D" must have the same node name.

How can I do this?
Any other options I have?

Thanks.

Comments

  • What you are describing with class A is a "factory" (Look up "Factory Pattern") and through Attributes you can control how things are displayed when serialized into XML.

    However it's still a little unclear of what your goals are:

    Can you describe what you are doing with the XML output?

    Part of the point of serialization is to be able to be reconstructed - so if two different classes actually have the same name, then one of them will not be able to be re-constructed through typical deserialization. So there might be another solution for your needs if you want to give a little more information.
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