Factory Method VS Factory Object

How do I understand the Factory Method Simple Factory and Factory Object is Abstract Factory? BUT:

- Factory Method (simple Factory):

public class SimplePizzaFactory { public static final int CHEESE = 1; public static final int PEPPERONI = 2; public static final int VEGGIE = 3; public static Pizza createPizza(int type) { Pizza pizza = null; if (type == CHEESE) { pizza = new CheesePizza(); } else if (type == PEPPERONI ) { pizza = new PepperoniPizza(); } else if (type == VEGGIE ) { pizza = new VeggiePizza(); } return pizza; } } 

Factory Object (Factory Summary):

?

I'm right?

How many factory template implementations are there and what are the differences?

+7
source share
1 answer

Not. A factory method is a factory that does not require any state. The factory class is the class itself β€” it has state and methods that change that state. At the end, you call the .create() method, and it uses its current state to create a new object of a different type.

A factory abstract is a completely different thing β€” there you have several factory implementations of the same abstract concept. An example of wikipedia is e GUIFactory - it is an abstract factory that has two implementations: WinFactory and OSXFactory . The client code does not know which implementation it uses - it just knows that the factory creates Button instances. This allows you to write the same code regardless of the OS.

+6
source

All Articles