[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Designing constructor for QName class

  • From: Frans Englich <frans.englich@t...>
  • To: xml-dev@l...
  • Date: Thu, 9 Nov 2006 11:11:45 +0100

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]


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.