Richard Kennard wrote:
Alan,

Thanks for your prompt reply! I appreciate you keeping this moving.

1. I would like to postpone the issues of method chaining and URI/URL creation to another discussion, if that's okay.
2. So what we are debating between here is...

   public UrlQueryString {
       private UrlQueryString();
       public static UrlQueryString create();
       public static UrlQueryString parse(CharSequence query);
      ...
   }

...versus...

   public UrlQueryString {
       public UrlQueryString()
       public UrlQueryString(CharSequence query)
      ...
   }

While both are roughly equivalent, I guess the latter seems more 'normal' to me, and more in keeping with the rest of the JDK?

Just so you know where I'm coming from - I am no longer thinking this class should be any kind of builder or factory, rather I think it should simply model a 'www-form-urlencoded' query string.
Josh Bloch's Effective Java provides many good reasons to prefer static factory methods over public constructors. In this context the ability to name the creation methods and the possibility of returning a subtype are probably the important ones. As this class evolves then it is possible there will be new ways to create these objects (the ability the specify the encoding, separator, etc. come to mind). Many of these creation methods will specify the configuration as Strings so allowing the creation names be distinguished even though they have the same signatures will be useful. In the case of subtypes, it may be that you want to have other types of query string in the future (as web standard tend to evolve).

-Alan.


Reply via email to