Professional Documents
Culture Documents
2. Builder
2. Builder
Director Builder
construct() buildPartA()
buildPartB()
new Director(aConcreteBuilder)
construct() buildPartA()
buildPartB()
buildPartC()
getResult()
When to use a Builder Pattern
• When the algorithm for building a complex
object should be independent of the parts
that make up the object and how they’re
assembled
• When the construction process must allow
different representations for the object that’s
constructed
• When building a composite structural object
Key Consequence of Builder
Pattern
• Vary a product’s internal representation
• Isolates code for construction and representation
Don’t forget that the Builder Design
Pattern also gives you finer control
over the construction process!
How to code a builder
• Assembly and Construction Interface
• No abstract class for products
• Empty methods as default in Builder
Class MazeBuilder {
Public:
virtual void BuildMaze() { }
virtual void BuildRoom(int room) { }
virtual void BuildDoor(int roomFrom, int roomTo) { }