The Builder pattern
Tom wasted no time getting into the weeds. “We talked about the possibilities of using the Builder pattern. I think it’s going to work really well,” Tom said.
Deftly moving the pointer around the screen with his big toe, he added the classes needed to implement the Builder pattern. You can see the result here:
Figure 6.17: Tom has added the structures required for the Builder pattern
We covered the parts of the pattern in detail in Chapter 3, Getting Creative with Creational Patterns, but let’s quickly review this:
- The builder is defined by an interface or an abstract class. Here, that will be
IWheelchairBuilder
. - The builder is controlled directly by a
WheelchairBuilderDirector
class that contains a private instance of the builder interface. All the work is done by the director. - Concrete instances of builders are defined for each product. In this case, each wheelchair model gets its own builder...