17.6 Using FactoryBuilderSupport

We’ll use ​FactoryBuilderSupport​ if we’re working with well-defined node names such as button, checkbox, label, and so on, in the ​SwingBuilder​. The ​BuilderSupport​ we saw in Section 17.5, Using BuilderSupport, is good for working with hierarchical structures. However, it’s not convenient for dealing with different types of nodes. Suppose we have to work with twenty different node types. Our implementation of ​createNode​ will get complicated. Based on the node name, we’ll create different nodes, which leads to a messy ​switch​ statement. Chances are we’ll quickly lean toward an abstract factory (see Design Patterns: Elements of Reusable Object-Oriented Software [GHJV95]) approach to create these nodes. ...

Get Programming Groovy 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.