Back to list
Views:   7.2K
Replies:  1
Archived

Builder Pattern what about parameters

Hello, in the examples, both here and elswewhere on the internet I see always something like this

public void Construct(Builder builder)

    {

      builder.BuildPartA();

      builder.BuildPartB();

    }
But what if the parts require parameters? How should I provide them? What if for one builder BuildPartA() requires parameters and for an other one it doesn't?
 
Peter G., Sep 30, 2012
Reply 1
Quickly put in here - you could optimize initializations as required (like Singleton etc.,)

Create and Entity Class that encapsulates all the parameters you may need for PartA,B as Properties

public class PartsDTO
{

string _Property1=string.empty; //for simplicity considered a string property
public string Property1
{
  get{return _Property1;}
set {_Property1=value;}
}

}


public class Builder
{

   public _PartsDTO=null;
   
   public PartsDTO PartsDTO
{
 get{return _PartsDTO;}
set{_PartsDTO=value;}


}

and within the construct method

public void Construct(Builder builder)

    {

      builder.BuildPartA(builder.PartsDTO.Property1);

      builder.BuildPartB();

    }



thanks,
Tarriq
Tarriq Ferrose Khan, Oct 01, 2012


Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Licensing       EULA       Sitemap      
© Data & Object Factory, LLC.
Made with    in Austin, Texas.      Vsn 1.2.2