Defines an interface used to create objects, so that the subclass determines which class to instantiate. The factory method delays the instantiation of a class to the subclass.
Static Graph
Intention Defines an interface used to create objects, so that the subclass determines which class to instantiate. Factory method to instantiate a class
Delay to its subclass.
Applicability When a class does not know the class of the object it must create.
When a class wants its subclass to specify the object it creates.
When a class delegates the responsibility of creating an object to one of multiple help sub-classes, and you want to localize the information of which help sub-classes are proxies.
Summary Factory method pattern does not use a special class to determine which subclass to instantiate. On the contrary, superclasses delay this decision to every subclass. This mode does not actually have a decision point, and does not directly select a decision for subclass instantiation. A program written in this mode defines an abstract class to create an object, but the subclass decides to create an object.
Source code + Visio
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service