I created a class following the Java builder pattern and it has been working great for me, however now I find myself needing a little more modularity. Can this be accomplished without scrapping the Builder?
For example I would like to build my Person objects with a configuration array of enums (or any other method that would let me customize the order and selection of fields). The values come in from various nested objects and I need certain fields at certain times in certain orders to create an output CSV.
public static enum FIELDS = { FIRST, MIDDLE, LAST }
List<FIELDS> fields = { FIRST, LAST } creates:
Person person = new Person.builder().first("john").last("doe").build();
List<FIELDS> fields = { LAST, FIRST, MIDDLE } creates:
Person person = new Person.builder().last("doe").first("john").middle("q").build();
Is it possible to do any kind of switch statements on an enum to construct a Person dynamically like this?