Use Builder pattern ( was: Re: Http client API)

Michael McMahon michael.x.mcmahon at oracle.com
Wed Aug 15 09:20:39 PDT 2012


On 09/08/12 10:50, Chris Hegarty wrote:
> On 09/08/12 00:00, Jed Wesley-Smith wrote:
>> Michael McMahon <michael.x.mcmahon at ...> writes:
>>
>>> A new revision of the Http client API planned for jdk 8 can be viewed
>>> at the following link
>>>
>>> http://cr.openjdk.java.net/~michaelm/httpclient/v0.3/
>>>
>>> We would like to review the api on this mailing list.
>>> So, all comments are welcome.
>>
>> Can you separate the domain objects (in particular HttpClient, 
>> HttpRequest)
>> and their set-up (all the mutators) into separate concerns (Builders 
>> perhaps,
>> see Guava for instance)?
>
> +1, I agree with your comment.
>
> Wherever possible we should try to use a builder pattern to build 
> immutable objects ( or limit its mutability as much as possible ). I 
> think Mike made a very similar comment too. Maybe the spi and 
> factory/builder could be separated out, I think this would be much 
> cleaner.
>
> As you say, you get thread-safety by default, which would appear to be 
> a nice property for this API, given its different programming models.
>
I agree. The various mutable set() type methods should be in builders 
and the resulting HttpClient and HttpRequests
should be immutable. Will look into that now.

Thanks,
Michael.





More information about the net-dev mailing list