FactoryBuilderSupport
BuilderSupport
is the base class for many of the builder classes provided in the Groovy packages. As we can see from the previous examples, it is easy to work with. We have built quite a useful database builder tool in relatively few lines of code.
However, one issue with BuilderSupport
is that the hook functions are in effect funnels for handling all of the possible tags that we might like to process in our markup. In our CustomerBuilder
, we are handling just four different tags.
This is not a realistic scenario for most database schemas. We could expect to have dozens more tag types that we need to handle if we wanted to expand this example into something that would work with a typical database schema for even a modestly sized application. Funneling all of these tags into one createNode
would create an unwieldy mess of code:
def createNode(name){ Object result = null switch (name) { case "customer": return new Customer(firstName:"", lastName:"...