Design Patterns Learn a simple factory model

Source: Internet
Author: User

Simple Factory mode

The first step is to create the parent class A (abstract class), abstract methods, and concrete variables

The second step is to create the factory class parent Class B, which is used to implement the Create abstract class A

The third step is to create a subclass C, inherit the parent Class A, overload the parent class method, write the method implementation, and assign the variable to the specific value.

Fourth, create the factory class D, inherit the factory class parent Class B, the subclass C that is used to create the concrete implementation

(Equivalent to AC is the template inside the factory)

(BD is a product produced inside the factory)

Simple Factory mode, memo

Design Patterns Learn a simple factory model

Contact Us

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: 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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.