Created
August 2, 2016 10:38
-
-
Save florianhoehn/e31e3051b056252c11f71aad3c4da721 to your computer and use it in GitHub Desktop.
more sophisticated builder pattern use case
This file contains 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
Contact testContact = new ContactBuilder() | |
.withFirstName('JP') | |
.withLastName('Coolio') | |
.withAccount(new AccountBuilder().withRecordType('Coder')) | |
.build(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Scenario: we want a contact record with the Name 'JP Coolio'. But we need an account to create a contact record. Usually what do we do? We create two methods in the TestDataFactory class, try to name them in a way that someone else can potentially find the methods again and we call both of the methods wherever we are creating the test data.
With the builder pattern, yes we have to build the infrastructure and when we do have it: voila, we can specify the creation of the account inside the contact as we really don't care about it that much anyway. It's neat. I think. :)