I am implementing a Builder Pattern to create a set of objects. Then these objects must be serialized into XML and deserialized from XML.
I know how to serialize and deserialize, but I'm not sure how to integrate it into a design template.
For example, suppose my code uses the builder to create foo and bar products. My first thought is to put serialization on everyone, because every product knows what to serialize.
My next thought was to put deserialization in Director or ConcreteBuilder.
What I don't like about this is that the serialization and deserialization functions will be in different places - one in the file for declaring foo and bar objects, and the other in the files for something else. I am worried that they may stop synchronizing with each other when I work on product classes.
My last thought was that the director or ConcreteBuilder were serializing and deserializing. What I don't like about this is that then the products must know which builder was used or know who the Director is.
To clarify - there are two situations when a product can be created:
- User clicks a button in the user interface
- User uploads XML project
source share