It's good news that all the classes extend a common base class or implement a common interface. Then
polymorphism lets you call the toXML() method without even knowing what kind of object you really have.
Let's say Vignette wasn't so kind as to make a common interface. I've been stuck in situations where the object coming in has no useful methods or common base or anything remotely good. I made a map of classnames to handlers:
That factory is just a glorified HashMap that can deal with objects that don't have defined handlers, maybe by throwing an exception or something.
In your case, since you have to do additional custom processing for each type, make the handler do more:
Either of these techniques is neat because we can add new event objects without touching this particular code. Vignette might send us a new implementation of KnowsHowToMakeXML or our map might have a new handler from configuration. Every class you don't have to modify is one less chance to break something.
[ November 03, 2006: Message edited by: Stan James ]