I'm trying to implement a checked builder pattern similar to how it's described in this: https://dev.to/schreiber_chris/creating-complex-objects-using-checked-builder-pattern
The result I'm trying to reach is as follows:
Builder builder = new Builder('TestVal')
.when('this').then(new Set<String> {'val1','val2'})
.when('that').then(new Set<String> {'val3','val4'});
And the resulting object would contain a collection with any number of whens with the associted thens e.g. a Map like this (the param for when() is unique):
'this' => ['val1','val2'],
'that' => ['val3','val4']
I'm struggling with a couple things:
- How to associate the values passed into
then()with the value passed intowhen() - How to require
then()be called afterwhen(). (e.g. -.when('this').when('that') //invalid
Aucun commentaire:
Enregistrer un commentaire