You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jclouds.apache.org by Ignasi Barrera <ig...@gmail.com> on 2014/04/23 20:57:59 UTC

Re: Domain Object Pattern for toString()

I think it is to make it easier for the subclasses to add their fields to
the "toString" result, by just overriding the "string()" one. IIRC the
TemplateOptions object is an example, where many providers have their
custom subclass.

Apart from that, I don't see the point in having such a separate method.
El 23/04/2014 20:34, "Jeremy Daggett" <je...@rackspace.com>
escribió:

> Hi there,
>
> I am going through some Swift API feedback and many of the model objects
> in jclouds use a toString() pattern like this:
>
>
>    @Override
>
>    public String toString() {
>
>       return string().toString();
>
>    }
>
>
>    protected ToStringHelper string() {
>
>       return toStringHelper(this)
>
>             .add("name", getName())
>
>             .add("uri", getUri())
>
>             .add("etag", getEtag())
>
>             .add("lastModified", getLastModified())
>
>             .add("metadata", getMetadata());
>
>    }
>
>
> Why do we need another protected method to create the ToStringHelper?
> Forgive my ignorance, but can someone please explain to me why we can’t
> write the above code as:
>
>
>    @Override
>
>    public String toString() {
>
>       return toStringHelper(this)
>
>             .add("name", getName())
>
>             .add("objectCount", getObjectCount())
>
>             .add("bytesUsed", getBytesUsed())
>
>             .add("anybodyRead", getAnybodyRead().orNull())
>
>             .add("metadata", getMetadata()).toString();
>
>    }
>
>
> Is it the case of “its always been done that way”? Insight appreciated,
> thanks! ;)
>
>
> /jd
>
>