Builder Pattern
Aşçı elinde tarif varsa pizzayı pisirebilir.
Her tarif bir builder interface.
interface PizzaBuilder
buildSouce()
buildBread()
class HawaiiPizzaBuilder implements PizzaBuilder
Pizza p;
buildSauce(p.buildSauce()) //implementation
buildBread(p.buildBread()) //implementation
class SpicyPizzaBuilder implements PizzaBuilder
Pizza p;
buildSauce(p.buildSauce()) //implementation
buildBread(p.buildBread()) //implementation
class Cook ( Director )
PizzaBuilder pizzaBuilder;
setPizzaBuilder(Pizzabuilder p )
constructPizza(pizzabuilder.buildSauce();pizzabuilder.buildBread();)
getPizza(pizzaBuilder.getPizza())
class BuilderExample {
main() {
Cook cook = new Cook();
PizzaBuilder hpizzabuilder = new HawaiiPizzaBuilder();
cook.setPizzaBuilder(hpizzabuilder);
cook.constructPizza();
cook.getPizza();
}
}
Search Blog
Friday, February 3, 2012
Builder Pattern ( Creational )
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment