Overview:
Factory method mode is the most widely used design pattern, after all, he is responsible for the creation of a series of objects, and object creation is the most tedious behavior in object-oriented programming. Gof in design mode, "Factory method mode causes the instantiation of a class to be deferred to a subclass." "Exactly, the Factory method pattern is the responsibility to create an object instance, transfer it to a factory class, and use abstract principles to delay the instantiation behavior to a specific factory class."
Intention:
Defines an interface for creating objects, allowing subclasses to decide which class to instantiate. The Factory method pattern delays the instantiation of a class to a subclass.
UML diagram:
A common example:
Animals--Cats, dogs, cows, sheep, pigs ... People know that animals are all shaped, they have their own different appearance (Display), is an animal he will eat food (most animals can eat, eat ...) )。 What is the shape of the concrete? How do they eat things? This is not what we need to be concerned about, and what we care about is how to create an example of a particular animal through a factory.