vendredi 5 juin 2015

Design a builder pattern

This is my usecase. How can i use builder pattern for this or is there any other pattern i can use for this. I have to build a object which contain multiple fields. But fields of the object will be filled on multiple steps of the API. The API is multithreaded and async. So the requirement is:

  1. Fill some fields in one step and store it and again next step will pick the object and fill the field and in the last when all the fields are filled object will be constructed. So that Object will be immutable in the last.
  2. As its a multithreaded environment so initially every request thread there should be one builder and one object. As the API is async if we cache the object and multiple threads needs to update the object field. But in the last it should be complete and immutable. How will i do that.
  3. Is there any other design pattern i can think of.

Aucun commentaire:

Enregistrer un commentaire