Created
May 24, 2013 02:16
-
-
Save JakeGinnivan/5640861 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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