Skip to content

Instantly share code, notes, and snippets.

@JakeGinnivan
Created May 24, 2013 02:16
Show Gist options
  • Select an option

  • Save JakeGinnivan/5640861 to your computer and use it in GitHub Desktop.

Select an option

Save JakeGinnivan/5640861 to your computer and use it in GitHub Desktop.
public class DomainClass
{
public DomainClass(AnotherDomainClass dep, string arg){
//logic
}
}
public class AnotherDomainClass{
public AnotherDomainClass(string arg, string arg2){
//ctor logic
}
}
// Builders
public class DomainClassBuilder
{
string _arg;
public DomainClass(string arg = "Good default value"){
_arg = arg;
}
public DomainClassBuilder WithAnother(AnotherDomainClass anotherDomainClass){
_anotherDomainClass = anotherDomainClass;
}
public DomainClassBuilder WithAnother(AnotherDomainClassBuilder anotherDomainClass){
_anotherDomainClass = anotherDomainClass.Build();
}
public DomainClass Build(){
return new DomainClass(_anotherDomainClass ?? new AnotherDomainClassBuilder("Some default"), _arg);
}
}
public class AnotherDomainClassBuilder{
string _arg1;
string _arg2;'
public AnotherDomainClassBuilder(string arg1 = "Good default", string arg2 = "Another good default") {
_arg1 = arg1;
_arg2 = arg2
}
public AnotherDomainClassBuilder Build(){
return new AnotherDomainClassBuilder(_arg1, _arg2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment