XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Designing constructor for QName class


Hi all,

Me and a co-worker was discussing how to design a constructor for a QName 
class and couldn't make up our minds. Which of the two(think in Java/C++ 
style) is the best constructor?

QName(String localName, String namespaceURI = String());

QName(String namespaceURI, String localName);

Here's how I see it. The latter forces the user to explicitly specify the 
namespace and therefore mistakes are avoided. On the other hand, for 
experienced users this could get a bit tedious when using the empty namespace 
a lot, but perhaps that's worth it when the return is less mistakes with 
namespaces?

The first alternative makes the (common) case of using the empty namespace 
easier, since that's the default argument. On the other hand, it also makes 
it possible for the user to not specify the namespace, and therefore end up 
with the wrong URI.

So, the former can let namespace mistakes through -- but that's not 
necessarily not a problem if it's trapped later on. Would it be, for a 
"typical" QName class? For example, a QName class compares to other QName 
instances in a namespace aware way(and is obviously also namespace aware when 
passed to serialization code, and so on), so wouldn't an incorrect namespace 
simply show up then? (assuming it shows up at all).

A third alternative is to only have a default constructor and instead 
completely rely on setters. Trolltech's Qt library use this style a lot for 
readability[1]:

QName name;
name.setLocalname("body");
name.setNamespaceURI("http://www.w3.org/1999/xhtml";);

However, I think it avoids the issue since it doesn't force the user to call 
setNamespaceURI().

I think my choice is QName(String localName, String namespaceURI = String()); 
because even if a constructor that allows ignoring reflecting on namespace 
selection, the namespace selection can go by unnoticed if the class has a 
default constructor. ...but if the class doesn't have a default ctor, is it 
then the other alternative that's best?

What's your thoughts on this, from your endeavors in designing and using QName 
classes?


Cheers,

		Frans
1.
For example, this:
Class(0, 1, 0);

is less readable than:

Class instance;
instance.setStartPosition(0);
instance.setIntervalPosition(1);
....


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS