[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xml-dev
Subject:    Re: [xml-dev] Designing constructor for QName class
From:       "Radu Cernuta" <radu.cernuta () gmail ! com>
Date:       2006-11-09 22:14:27
Message-ID: 5d4dd4470611091414h13ca7403l807ec6ba84caeb08 () mail ! gmail ! com
[Download RAW message or body]

I supose by
"QName(String lname, String namespace = String())"
you mean something like

class QName{
    private String namespaceURI;
    private String localName;

    public QName(String ln){
        this.localName = ln;
        namespaceURI = new String();
    }
}

This si indeed a possibility, but in many cases you might need more, like,
for instance, to actually pass a namespaceURI to a constructor, or even a
prefix. So you can overload the constructor. Like this:

class QName{
    private String namespaceURI;
    private String localName;
    private String prefix;

    public QName(String ln){
        this.localName = ln;
        namespaceURI = new String();
        prefix = new String();
    }

    public QName(String ln, String nu){
         this.localName = ln;
        namespaceURI = nu;
        prefix = new String();
    }

    public QName(String ln, String nu, String px){
        .....
    }
}
This way the experienced users can use what suits them best.

You can also take a look at this:
http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/namespace/QName.html

Chances are you have already a QName class at your disposal and you don't
have to design any constructors.

Greetings,
Radu

2006/11/9, Frans Englich <frans.englich@telia.com>:
>
> On Thursday 09 November 2006 13:32, Richard Salz wrote:
> > Why not just
> >         QName(String lname)
> >         QName(String nspfx, String lname)
>
> How is that different from:
>
>         QName(String lname, String namespace = String())
>
> except for the order of the arguments?
>
>
> Cheers,
>
>                 Frans
>
> _______________________________________________________________________
>
> XML-DEV is a publicly archived, unmoderated list hosted by OASIS
> to support XML implementation and development. To minimize
> spam in the archives, you must subscribe before posting.
>
> [Un]Subscribe/change address: http://www.oasis-open.org/mlmanage/
> Or unsubscribe: xml-dev-unsubscribe@lists.xml.org
> subscribe: xml-dev-subscribe@lists.xml.org
> List archive: http://lists.xml.org/archives/xml-dev/
> List Guidelines: http://www.oasis-open.org/maillists/guidelines.php
>
>

[Attachment #3 (text/html)]

I supose by <br>&quot;QName(String lname, String namespace = String())&quot;<br>you \
mean something like<br><br>class QName{<br>&nbsp;&nbsp;&nbsp; private String \
namespaceURI;<br>&nbsp;&nbsp;&nbsp; private String localName;<br>&nbsp;&nbsp;&nbsp; \
<br>&nbsp;&nbsp;&nbsp; public QName(String ln){ <br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; this.localName = ln;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
namespaceURI = new String();<br>&nbsp;&nbsp;&nbsp; }<br>}<br><br>This si indeed a \
possibility, but in many cases you might need more, like, for instance, to actually \
pass a namespaceURI to a constructor, or even a prefix. So you can overload the \
constructor. Like this: <br><br>class QName{<br>&nbsp;&nbsp;&nbsp; private String \
namespaceURI;<br>&nbsp;&nbsp;&nbsp; private String localName;<br>&nbsp;&nbsp;&nbsp; \
private String prefix;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; public \
QName(String ln){<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this.localName = \
ln;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; namespaceURI = new String(); \
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; prefix = new \
String();<br>&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; public QName(String ln, \
String nu){<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; this.localName = ln;<br> \
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; namespaceURI = nu;<br> &nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; prefix = new String();<br>&nbsp;&nbsp;&nbsp; \
}<br><br>&nbsp;&nbsp;&nbsp; public QName(String ln, String nu, String \
px){<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; .....<br>&nbsp;&nbsp;&nbsp; \
}<br>}<br>This way the experienced users can use what suits them best.<br><br>You can \
also take a look at this: <br><a \
href="http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/namespace/QName.html">http://j \
ava.sun.com/j2se/1.5.0/docs/api/javax/xml/namespace/QName.html</a><br><br>Chances are \
you have already a QName class at your disposal and you don't have to design any \
constructors. <br><br>Greetings,<br>Radu<br><br><div><span \
class="gmail_quote">2006/11/9, Frans Englich &lt;<a \
href="mailto:frans.englich@telia.com">frans.englich@telia.com</a>&gt;:</span><blockquote \
class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt \
0pt 0.8ex; padding-left: 1ex;"> On Thursday 09 November 2006 13:32, Richard Salz \
wrote:<br>&gt; Why not just<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
QName(String lname)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
QName(String nspfx, String lname)<br><br>How is that different \
from:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QName(String lname, \
String namespace = String()) <br><br>except for the order of the \
arguments?<br><br><br>Cheers,<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& \
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Frans<br><br>_______________________________________________________________________<br><br>XML-DEV \
is a publicly archived, unmoderated list hosted by OASIS <br>to support XML \
implementation and development. To minimize<br>spam in the archives, you must \
subscribe before posting.<br><br>[Un]Subscribe/change address: <a \
href="http://www.oasis-open.org/mlmanage/">http://www.oasis-open.org/mlmanage/ \
</a><br>Or unsubscribe: <a \
href="mailto:xml-dev-unsubscribe@lists.xml.org">xml-dev-unsubscribe@lists.xml.org</a><br>subscribe: \
<a href="mailto:xml-dev-subscribe@lists.xml.org">xml-dev-subscribe@lists.xml.org</a><br>List \
archive:  <a href="http://lists.xml.org/archives/xml-dev/">http://lists.xml.org/archives/xml-dev/</a><br>List \
Guidelines: <a href="http://www.oasis-open.org/maillists/guidelines.php">http://www.oasis-open.org/maillists/guidelines.php
 </a><br><br></blockquote></div><br>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic