Transitioning to a Fluent Builder structure
As you’re digesting the code we’ve written so far, your spidey senses might have pointed out that the Builder pattern feels kind of static. That’s not to say it’s not useful as-is, but having each component hardcoded in its respective concrete builder doesn’t allow for much customization, which makes the basic pattern only useful in rigid scenarios. You’ll be able to do away with the director (which isn’t a bad thing), allowing you to create objects in a more reusable way. You’ve likely run into fluent builders in your C# travels without knowing it; the StringBuilder
class is usually the most recognizable example, which lets you chain method calls together in a desired sequence without line breaks, which is the structure we’ll copy in the last section here.
Transforming the IBuilder
interface and concrete builders into fluent builders only requires a slight syntax tweak to...