2 Replies Latest reply on Dec 29, 2010 5:02 PM by 827328

    Help: Should I use Abstract Factory or Builder Pattern?


      Could any expert here please give some guideline? I am planning to implement something and considering using either Abstract Factory or Builder pattern based on what I read about both. However, I am unable to determine which one would be best used in this situation. Here is what I have -

      1. I have a Object "MyObject" that contains some fields.
      2. I need to use helper class/classes to set another "CallObject" based on fields in "MyObject". This helper class(es) reads values from "MyObject" and further compute it and set fields in "CallObject".
      3. This "CallObjects" gets passed to external sdk method, which performs certain operation and returns "ResponseCallObject".
      4. This "ResponseCallObject" then needs to be converted into "ResponseMyObject". Here I have to use again helper class(es) to read "ResponseCallObject" and further computer it and then set fields in "ResponseMyObject"

      For steps 2 and 4, I would have to execute multiple methods in helper class(es) to set object correctly.

      I hope I was able to explain the problem properly above. Based on what I read, I believe Abstract Factory or Builder Pattern would be a good choice to implement. But I am not sure which one would be the best solution as it seems when multiple steps are required to "build" object, the builder pattern would be good to use.

      I need help on two things from anyone generous enough to help here :-)

      1.) Is Builder pattern best to implement here?
      2.) If I have to use either Builder Pattern (or Abstract Factory), could someone provide a hint on how my class structure would look like. (i.e. what goes in Director, Builder, Product etc.)

      I will appreciate if anyone can throw some light on it.