Home > Common Problem > What are the applicable scenarios for the factory method pattern?

What are the applicable scenarios for the factory method pattern?

藏色散人
Release: 2020-07-01 10:25:13
Original
7586 people have browsed it

The applicable scenarios of the factory method pattern include: 1. When a class does not know the class of the object it must create; 2. When a class wants its subclass to specify the object it creates. 3. When a class delegates the responsibility of creating objects to one of multiple helper subclasses, and you want to localize the information about which helper subclass is the delegate.

What are the applicable scenarios for the factory method pattern?

Factory Method Pattern

Define an interface for creating objects and let subclasses determine the instances Which class to use. Factory methods enable deferring instantiation of a class to its subclasses

Applicability

  • When a class does not know the objects it must create When a class

  • When a class wants its subclass to specify the object it creates

  • When the class will create When delegating an object's responsibilities to one of multiple helper subclasses, and you want to localize information about which helper subclass is the delegate

More related For knowledge, please visit PHP中文网!

The above is the detailed content of What are the applicable scenarios for the factory method pattern?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template