Re: Serialization
dmcreyno wrote:
I have a need to export an object hierarchy to several different
formats (xml, pdf, msword, etc). Each format will contain unique
information about the obejcts. For instance, the word doc might contain
information about the object's depth in the structure while the pdf
version omits this info.
I was trying to play around with serialization (as opposed to
toString()), so that I could encapsulate the unique behaviors in
decorator classes. That way, to change the protocl, all I need to do is
change the decorator. If I need a new protocol, then the only existing
code that gets changed is the decorator factory and the client making
use of the factory. The underlying algorithm should be unaltered.
I've had somewhat limit success with Externalizable. thoughts? ideas?
am i smoking crack?
I say its the crack....
What you probably want to look into is MVC.
You have a model, and I assume some sort of controller, what your
stated requirements ask for is a set of views. and XML view, a PDF
view, etc... Each view should be implemented to be independant of the
Controller (Application logic manipulating the Model), and should only
rely on observable properties of the Model (the Model, in good design,
should handle domain logic, and only expose what is necessary for the
View to render.)
The Model shouldn't be dependent on either the Controller or any of the
View's.
Look into templating technology to implement your Views. If this is a
webapp, JSP's could work nicely. Also look into Velocity or
Freemarker. You might also want to look into existing PDF generating
API's.
Hope this helps.
- Daniel.