Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] Canonicalizer and Serializer could implement a common interface

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Janek Bogucki <janekdb AT yahoo.co.uk>
  • To: xom-interest AT lists.ibiblio.org
  • Subject: [XOM-interest] Canonicalizer and Serializer could implement a common interface
  • Date: Fri, 21 Nov 2003 00:16:45 +0000 (GMT)

Canonicalizer is no longer a subclass of Serializer but they can be united
from a client's point
of view with an appropriate interface.

By introducing an interface containing the key client method implemented by
Canonicalizer and
Serializer it becomes easier to write generic code, including mock objects
which are useful in
unit tests.

In order to give the interface a generic name, Serializer would be renamed to
XMLSerializer. The
interface would then be:

public interface Serializer {

void write(Document doc) throws IOException ;

}

The existing classes then implement this interface:

public class XMLSerializer implements Serializer {...}
public class Canonicalizer implements Serializer {...}

This opens the possibility of implementing non-XML serializers which a client
coded to the
Serializer interface could use transparently.

MyTask task = new MyTask ( document, getMyNonXMLSerializer () ) ;
task.execute();

MyTask task2 = new MyTask ( document, getCanonicalizer () ) ;
task2.execute();

Where the additon of a new type lies, in terms of the 80/20 rule, I can not
say but programming to
interfaces is generally a good idea.

I did reread http://www.ibiblio.org/xml/XOM/designprinciples.xhtml#d0e206
'Prefer classes to
interfaces'. Since the focus of this argument is the prevention of the
creation of object models
which represent non-wellformed XML it doesn't apply strongly here.

-Janek

________________________________________________________________________
Want to chat instantly with your online friends? Get the FREE Yahoo!
Messenger http://mail.messenger.yahoo.co.uk




Archive powered by MHonArc 2.6.24.

Top of Page