Factory Method
- 作者:xiaoxiao
- 发表时间:2020-12-23 11:02
- 来源:未知
BenefitsIt removes the need to bind application-specific classes into the code. The code interacts solely with the resultant interface, so it will work with any classes that implement that interface.Because creating objects inside a class is more flexible than creating an object directly, it enables the subclass to provide an extended version of an object.
Applicable ScenariosA class is not able to anticipate the class of objects it needs to create.A class wants its subclasses to specify the objects it instantiates.Classes assign responsibility to one of several helper subclasses, and you want to localize the knowledge of which helper subclass is the delegate.