CS 535 Object-Oriented Programming & Design Spring Semester, 1999 Builder |
||
---|---|---|
© 1999, All Rights Reserved, SDSU & Roger Whitney San Diego State University -- This page last updated 15-Apr-99 |
Builder
Intent
Separate the construction of a complex object from its representation so that the same construction process can create different representations
Applicability
Use the Builder pattern when
Sample Builder Interface
class MazeBuilder { void buildMaze() { } void buildRoom( roomData ) { } void buildDoor( doorData ) { } void buildCorridor( corridorData ) { } // Call this when maze is complete Maze getMaze() { } } The builder know how to build mazes step by step The builder does not know what maze you wish to build A separate object, a director, knows the steps needed to construct a particular maze, but does not know how to build mazes or room, etc.
Collaborations
The client creates the Director object and configures it with the desired Builder object
Director notifies the builder whenever a part of the product should be built
Builder handles requests from the director and adds parts to the product
The client retrieves the product from the builder
Consequences
It lets you vary a product's internal representation
It isolates code for construction and representation
It gives you finer control over the construction process
Copyright ©, All rights reserved.
1999 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA.
OpenContent license defines the copyright on this document.
Previous    visitors since 15-Apr-99    Next