Design Patterns: Builder

Posted by Monik, 12 October 2010.
Programming Code Design Design Patterns
Book summary
Summary on basis of the book ,,Design Patterns: Elements of Reusable Object-Oriented Software'', by Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides, Addison-Wesley, 1995.

class Direcor {
getRepresentation(){
...
for (..){
builder.addPart(in.readLine());
}
...
}
}
We use this when we want to separate the algorithm for creating an object from the structure of the thing based on which we create it.

This is often used for conversions: the Director parses input data and calls the the Builder's methods for creating the object. The Builder's same methods are called multiple times for each piece of data. At the end we can retrieve constructed object from the Builder. We can have many different Builders, each converting to different format.

Variations:

Comments


Comments: