C # design pattern series: simple factory)

Source: Internet
Author: User

1. Introduction to the simple factory Model

1.1>, definition

The simple factory mode defines a factory class, which can return instances of different classes according to different parameters. The created instances usually have a common parent class.

In simple factory mode, only one factory class is required.

The simple factory mode is also called the static factory mode. The factory class is a static class or contains a static method.

1.2>. Usage Frequency

Medium

2. Simple factory mode structure

2.1>, structure chart

 

2.2> participants

Participants in the simple factory model:

Abstract product: Abstract product class. It abstracts and extracts common code of a specific product class and encapsulates it in an abstract product class.

◊ Concreteproduct: A product class that encapsulates the code of various product objects to be created into a specific product class.

Factory: A factory class that provides a factory class for creating various products and a factory method for creating products in the factory class, this method can create different product Objects Based on different input parameters.

Consumer Client: client class. You only need to call the factory method of the factory class and input the corresponding parameters to obtain a product object.

3. Simple factory mode structure implementation

 

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.