jclouds-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ignasi Barrera <ignasi.barr...@gmail.com>
Subject Re: Domain Object Pattern for toString()
Date Wed, 23 Apr 2014 18:57:59 GMT
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" <jeremy.daggett@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
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message