Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have below class which builds reference data for my app, do you think it's a good implementation of builder pattern. What can I change to improve it?

public class ReferenceDataBuilder
    {
        private readonly List<Task> _builderTasks;
        private IDataProvider _dataAccess;
        private ReferenceData _referenceData;


        public ReferenceDataBuilder(IDataProvider dataAccess)
        {
            ValidationUtils.ArgumentNotNull(dataAccess, "dataAccess");

            _dataAccess = dataAccess;

            _referenceData = new ReferenceData();
            _builderTasks = new List<Task>();
            createBuilderTasks();
        }

        public virtual ReferenceData BuildAsync()
        {
            Parallel.ForEach(_builderTasks, (task) => { task.Start(); task.Wait(); });
            return _referenceData;
        }


        private void createBuilderTasks()
        {
            _builderTasks.Add(new Task(() => _referenceData.Object1 = _dataAccess.GetObject1()));
            _builderTasks.Add(new Task(() => _referenceData.Object2 = _dataAccess.GetObject2()));
            _builderTasks.Add(new Task(() => _referenceData.Object3 = _dataAccess.GetObject3());
            _builderTasks.Add(new Task(() => _referenceData.Object4 = _dataAccess.GetObject4());
        }
    }

Usage:

new ReferenceDataBuilder(dataAccess).BuildAsync();

Thanks

share|improve this question

put on hold as off-topic by Mat's Mug 2 days ago

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

1  
What's up with the unused fields _withPersistence and _persistenceDirectory? Please edit your actual code into the question, and note that your post's title should tell us what your code is doing; "builder pattern" doesn't tell us much, especially when the code presented isn't implementing the said pattern. – Mat's Mug 2 days ago
    
Corrected, thanks. Please verify if the builder pattern usage is right? – Deepak 2 days ago
    
That's your actual code? Your reference data consists of Object1, Object2, Object3 and Object3 properties? FWIW no, this isn't a builder pattern. Please see How to Ask for guidance on making your question a better fit for this site. – Mat's Mug 2 days ago
    
Thats not actual code, it's obfuscated for obvious reasons. – Deepak 2 days ago
    
Obfuscated for obvious reasons = OFF-TOPIC. For legal reasons. Contact your legal department and ask them whether it's okay to sublicense part of the code as CC-BY-SA (or MIT, have them look into it) so that you can get it reviewed. – Pimgd 2 days ago