lundi 15 février 2016

Best Creational Design Pattern to use

I am working on some code that needs to abstract the creation of an HttpClient. The Http Client will be an instance of the org.apache.http.client.HttpClient. The configuration of the Http Client will vary based on configuration information (i.e. is it a post/get request,basic auth, maybe some headers, etc).

To implement this I was thinking of using the Factory design pattern which would abstract the creation of the Http Clients;however, I wanted to know if the Builder pattern would be a better alternative.

I have looked at a couple of posts on this topic (see below) and it seems that the main difference is the complexity required in creating the instance. In one of the posts below it says that a Factory is a wrapper around constructors and when the factory creates the object everything should be done on one line.

Question: 1. If the creation of the HttpClient needs to do some additional steps (i.e create an instance, set some parameters, etc) am I breaking the Factory pattern and should use a builder?

Similar posts:

  1. What is the difference between Builder Design pattern and Factory Design pattern?

  2. http://ift.tt/1Qh8RKA

  3. Difference between Abstract factory and builder?

Aucun commentaire:

Enregistrer un commentaire