Application of Factory mode

Source: Internet
Author: User

Recently read some information about design patterns, just can use the factory model to organize some of the previous summary of the payment class and landing class

Factory mode, which simply means using a class to instantiate other classes and eventually return objects of that class. For example, a workshop factory, specializing in the production of BMW, Mercedes-Benz, Laus Ross and other cars, then abstract into class, the workshop plant is a factory class, BMW, Mercedes-Benz, Laus Ross is an object, through this factory class to produce an object, this mode is the Factory mode.

Previously summarized payment interfaces, now sorted using Factory mode

1. Establishment of factory class

The various payment classes are instantiated by means of a parameter ($name)

2. Payment Class

(1) Epay

(2) Wpay

By passing the value of the $name (Epay,wpay), instantiating the corresponding payment class, returning the object after calling its payment method, can complete the payment, when there is a new payment class interface need to expand, no need to change any code can continue to use the factory, extensibility is very strong.

With tp3.2, this article is simply a description of the combination of Factory mode integration of various payment classes.

Application of Factory mode

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

  • 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.