Difference between abstract factory and builder?

Sorry for the re-assignment. I searched through the Internet, but could not understand, so I have to post here. This is what I explore myself. I studied the first sample of head design.

Abstract factory template:

According to the differences, I learned that I built some feelings, this is Factory, but it creates only one type, most of the time.
So can I say that the NYStore in the image is above the builder as it returns the pizza object to the client? I'm right? Please give your answer on the basis of the above example, which may help me study it.

+4
source share
3 answers

. , Builder, GoF.

, "" . NyPizzaStore createPizza(), () NY, PizzaChef, , , , . ( / PizzaIngerdientFactory Recipe, ). , PizzaChef.createPizza(Recipe r). PizzaChef , , . ... PizzaChef, () .

, , , NewHavenStyle, , NYStyle, BrickFiredThinCrust. . Recipe .

, , :)


, ( , , //) . , .

Builder Director, createSomething() ( ). . Director (). , , , . , , . PizzaChef , . . - Customer.

, Abstract Factory Factory Methods ( ), Builder, Abstract Factory. AbstractFactory. Recipe AbstractFactory, NyStyleRecipe Recipe , PizzaChef . Directpr Builder , .

, , , Builder, , , Builder . Recipe , . NY. New Haven .

Recipe newyorkStyle = new Recipe(
   new ThinCrustBuilder(), 
   new RedSauceBuilder(), 
   new FreshClamsBuilder(), 
   new ElectricOvenBuilder());

Recipe newhavenStyle = new Recipe(
   new ThinCrustBuilder(), 
   new WhiteSauceBuilder(), 
   new FreshClamsBuilder(), 
   new BrickOvenBuilder());

PizzaChef chef = new PizzaChef ();

nyPizza = checf.createPizza(newyorkStyle);

nhPizza = checf.createPizza(newhavenStyle);

, . Abstract Factory

, !

+9

Builder Abstract Factory , . Builder , , Factory , . Builder . . .

( ) ProductA ProductB, , Product builder , , .

+3

, NYstore , productA, produtB... .. , NYStore pizzachef ( tcarvin), , , ( ) , : , , , .

.

enter image description here

liviu .

-1

Source: https://habr.com/ru/post/1548060/


All Articles