Kratos

A responsible theme for WordPress

Factory Method

definition

《Factory Method 》 Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.

Frequency of use: 《Factory Method 》  high

《Factory Method 》

 

UML class diagram

 

《Factory Method 》

participants

The classes and/or objects participating in this pattern are:

  • Product  (Page)
    • defines the interface of objects the factory method creates
  • ConcreteProduct  (SkillsPage, EducationPage, ExperiencePage)
    • implements the Product interface
  • Creator  (Document)
    • declares the factory method, which returns an object of type Product. Creator may also define a default implementation of the factory method that returns a default ConcreteProduct object.
    • may call the factory method to create a Product object.
  • ConcreteCreator  (Report, Resume)
    • overrides the factory method to return an instance of a ConcreteProduct.
点赞

发表评论

邮箱地址不会被公开。 必填项已用*标注