Skip to main content
deleted 1 character in body
Source Link
JanDotNet
  • 8.5k
  • 2
  • 20
  • 48

I like the syntax of your builder. Instead of having a contructor with multiple overloads, your builder provides a readable and very flexible solution. For instance

var service = Service.Builder
    .UsingProvider(provider)
    .WithValue("ValueA")
    .ExcludingOptions("OptionB", "OptionC")        
    .Create();

looks much better than something than

var excludeOptions = new string[] {"OptionB", "OptionC"};
var service = new Service(provider, "ValueA", excludeOptions);

However, if the constructoreconstructor becomes to complex, its probably the time to split the class in multiple classes (if possible) ;). For simple constructors (with 1-2 parameters) the implementation of the builder is too much effort. But for the few use cases that remain it seems to be a good alternative to "monster constructors". :).

I like the syntax of your builder. Instead of having a contructor with multiple overloads, your builder provides a readable and very flexible solution. For instance

var service = Service.Builder
    .UsingProvider(provider)
    .WithValue("ValueA")
    .ExcludingOptions("OptionB", "OptionC")        
    .Create();

looks much better than something than

var excludeOptions = new string[] {"OptionB", "OptionC"};
var service = new Service(provider, "ValueA", excludeOptions);

However, if the constructore becomes to complex, its probably the time to split the class in multiple classes (if possible) ;). For simple constructors (with 1-2 parameters) the implementation of the builder is too much effort. But for the few use cases that remain it seems to be a good alternative to "monster constructors". :).

I like the syntax of your builder. Instead of having a contructor with multiple overloads, your builder provides a readable and very flexible solution. For instance

var service = Service.Builder
    .UsingProvider(provider)
    .WithValue("ValueA")
    .ExcludingOptions("OptionB", "OptionC")        
    .Create();

looks much better than something than

var excludeOptions = new string[] {"OptionB", "OptionC"};
var service = new Service(provider, "ValueA", excludeOptions);

However, if the constructor becomes to complex, its probably the time to split the class in multiple classes (if possible) ;). For simple constructors (with 1-2 parameters) the implementation of the builder is too much effort. But for the few use cases that remain it seems to be a good alternative to "monster constructors". :).

Source Link
JanDotNet
  • 8.5k
  • 2
  • 20
  • 48

I like the syntax of your builder. Instead of having a contructor with multiple overloads, your builder provides a readable and very flexible solution. For instance

var service = Service.Builder
    .UsingProvider(provider)
    .WithValue("ValueA")
    .ExcludingOptions("OptionB", "OptionC")        
    .Create();

looks much better than something than

var excludeOptions = new string[] {"OptionB", "OptionC"};
var service = new Service(provider, "ValueA", excludeOptions);

However, if the constructore becomes to complex, its probably the time to split the class in multiple classes (if possible) ;). For simple constructors (with 1-2 parameters) the implementation of the builder is too much effort. But for the few use cases that remain it seems to be a good alternative to "monster constructors". :).