by james sheets. an object creational pattern. separates the construction of a complex object from...
TRANSCRIPT
![Page 1: By James Sheets. An object creational pattern. Separates the construction of a complex object from its representation so that the same construction process](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f225503460f94c3a9be/html5/thumbnails/1.jpg)
By James Sheets
![Page 2: By James Sheets. An object creational pattern. Separates the construction of a complex object from its representation so that the same construction process](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f225503460f94c3a9be/html5/thumbnails/2.jpg)
An object creational pattern.
Separates the construction of a complex object from its representation so that the same construction process can create different representations.
![Page 3: By James Sheets. An object creational pattern. Separates the construction of a complex object from its representation so that the same construction process](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f225503460f94c3a9be/html5/thumbnails/3.jpg)
1. An object requires different representations in different contexts
2. How a complex object is constructed is important
3. You need to encapsulate the logic behind constructing a complex object
![Page 4: By James Sheets. An object creational pattern. Separates the construction of a complex object from its representation so that the same construction process](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f225503460f94c3a9be/html5/thumbnails/4.jpg)
Convert an internal object into various file formats (pdf, doc)
Building a maze. Create a map, start point, end point, and then the maze walls.
![Page 5: By James Sheets. An object creational pattern. Separates the construction of a complex object from its representation so that the same construction process](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f225503460f94c3a9be/html5/thumbnails/5.jpg)
Director
Constructor()
Builder
BuildPart() : void
ConcreteBuilder
BuildPart() : void
GetResult() : Product
ProductFor all objects in builder { builder->BuildPart();}
For all objects in builder { builder->BuildPart();}
builder
![Page 6: By James Sheets. An object creational pattern. Separates the construction of a complex object from its representation so that the same construction process](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f225503460f94c3a9be/html5/thumbnails/6.jpg)
Director
Constructor()
Builder
BuildPart() : void
ConcreteBuilder
BuildPart() : void
GetResult() : Product
ProductFor all objects in builder { builder->BuildPart();}
For all objects in builder { builder->BuildPart();}
builder
![Page 7: By James Sheets. An object creational pattern. Separates the construction of a complex object from its representation so that the same construction process](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f225503460f94c3a9be/html5/thumbnails/7.jpg)
Director
Constructor()
Builder
BuildPart() : void
ConcreteBuilder
BuildPart() : void
GetResult() : Product
ProductFor all objects in builder { builder->BuildPart();}
For all objects in builder { builder->BuildPart();}
builder
![Page 8: By James Sheets. An object creational pattern. Separates the construction of a complex object from its representation so that the same construction process](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f225503460f94c3a9be/html5/thumbnails/8.jpg)
Director
Constructor()
Builder
BuildPart() : void
ConcreteBuilder
BuildPart() : void
GetResult() : Product
ProductFor all objects in builder { builder->BuildPart();}
For all objects in builder { builder->BuildPart();}
builder
![Page 9: By James Sheets. An object creational pattern. Separates the construction of a complex object from its representation so that the same construction process](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f225503460f94c3a9be/html5/thumbnails/9.jpg)
Director
Constructor()
Builder
BuildPart() : void
ConcreteBuilder
BuildPart() : void
GetResult() : Product
ProductFor all objects in builder { builder->BuildPart();}
For all objects in builder { builder->BuildPart();}
builder
![Page 10: By James Sheets. An object creational pattern. Separates the construction of a complex object from its representation so that the same construction process](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f225503460f94c3a9be/html5/thumbnails/10.jpg)
Director
Constructor()
Builder
BuildPart() : void
ConcreteBuilder
BuildPart() : void
GetResult() : Product
ProductFor all objects in builder { builder->BuildPart();}
For all objects in builder { builder->BuildPart();}
builder
![Page 11: By James Sheets. An object creational pattern. Separates the construction of a complex object from its representation so that the same construction process](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f225503460f94c3a9be/html5/thumbnails/11.jpg)
Director
Constructor()
Builder
BuildPart() : void
ConcreteBuilder
BuildPart() : void
GetResult() : Product
ProductFor all objects in builder { builder->BuildPart();}
For all objects in builder { builder->BuildPart();}
builder
![Page 12: By James Sheets. An object creational pattern. Separates the construction of a complex object from its representation so that the same construction process](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f225503460f94c3a9be/html5/thumbnails/12.jpg)
Director
Constructor()
Builder
BuildPart() : void
ConcreteBuilder
BuildPart() : void
GetResult() : Product
ProductFor all objects in builder { builder->BuildPart();}
For all objects in builder { builder->BuildPart();}
builder
![Page 13: By James Sheets. An object creational pattern. Separates the construction of a complex object from its representation so that the same construction process](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f225503460f94c3a9be/html5/thumbnails/13.jpg)
![Page 14: By James Sheets. An object creational pattern. Separates the construction of a complex object from its representation so that the same construction process](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f225503460f94c3a9be/html5/thumbnails/14.jpg)
Waiter
Waiter(PizzaBuilder)GetPizza() : PizzaConstructPizza() : void
PizzaBuilder
GetPizza() : PizzaBuildDough() : voidBuildSauce() : voidBuildToppings() : void
HawaiianPizzaBuilder
BuildDough() : voidBuildSauce() : voidBuildToppings() : void
SpicyPizzaBuilder
BuildDough() : voidBuildSauce() : voidBuildToppings() : void
Pizza
SetDough(String) : voidSetSauce(String) : voidSetToppings(String) : void
![Page 15: By James Sheets. An object creational pattern. Separates the construction of a complex object from its representation so that the same construction process](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f225503460f94c3a9be/html5/thumbnails/15.jpg)
/** "Product" */class Pizza {
private String dough = ""; private String sauce = ""; private String topping = "";
public void setDough (String dough) { this.dough = dough; } public void setSauce (String sauce) { this.sauce = sauce; } public void setTopping (String topping) { this.topping = topping; }
}
![Page 16: By James Sheets. An object creational pattern. Separates the construction of a complex object from its representation so that the same construction process](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f225503460f94c3a9be/html5/thumbnails/16.jpg)
/** "Abstract Builder" */ abstract class PizzaBuilder {
protected Pizza pizza;
public void PizzaBuilder() {
pizza = new Pizza(); } public Pizza getPizza() { return pizza; }
public abstract void buildDough(); public abstract void buildSauce(); public abstract void buildTopping();
}
![Page 17: By James Sheets. An object creational pattern. Separates the construction of a complex object from its representation so that the same construction process](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f225503460f94c3a9be/html5/thumbnails/17.jpg)
/** "ConcreteBuilder" */ class HawaiianPizzaBuilder extends PizzaBuilder {
public void buildDough() { pizza.setDough("cross"); } public void buildSauce() { pizza.setSauce("mild"); } public void buildTopping() { pizza.setTopping("ham+pineapple"); }
}
/** "ConcreteBuilder" */ class SpicyPizzaBuilder extends PizzaBuilder {
public void buildDough() { pizza.setDough("pan baked"); } public void buildSauce() { pizza.setSauce("hot"); } public void buildTopping() { pizza.setTopping("pepperoni+salami"); }
}
![Page 18: By James Sheets. An object creational pattern. Separates the construction of a complex object from its representation so that the same construction process](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f225503460f94c3a9be/html5/thumbnails/18.jpg)
/** "Director" */ class Waiter {
private PizzaBuilder pizzaBuilder;
public Waiter(PizzaBuilder pb) { pizzaBuilder = pb; }public Pizza getPizza() { return pizzaBuilder.getPizza(); } public void constructPizza() {
pizzaBuilder.buildDough(); pizzaBuilder.buildSauce(); pizzaBuilder.buildTopping();
} }
![Page 19: By James Sheets. An object creational pattern. Separates the construction of a complex object from its representation so that the same construction process](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f225503460f94c3a9be/html5/thumbnails/19.jpg)
/** A customer ordering a pizza. */ class BuilderExample {
public static void main(String[] args) {
// ConcreteBuilder cast as a BuilderPizzaBuilder hawaiian= new HawaiianPizzaBuilder(); // DirectorWaiter waiter = new Waiter(hawaiian);
waiter.constructPizza(); // ProductPizza pizza = waiter.getPizza();
} }
![Page 20: By James Sheets. An object creational pattern. Separates the construction of a complex object from its representation so that the same construction process](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f225503460f94c3a9be/html5/thumbnails/20.jpg)
Concrete Builders create families of objects, like an Abstract Factory
Abstract Factory returns the family of related objects
Builders construct a complex object one step at a time
![Page 21: By James Sheets. An object creational pattern. Separates the construction of a complex object from its representation so that the same construction process](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f225503460f94c3a9be/html5/thumbnails/21.jpg)
![Page 22: By James Sheets. An object creational pattern. Separates the construction of a complex object from its representation so that the same construction process](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f225503460f94c3a9be/html5/thumbnails/22.jpg)