From 0 self-taught c#09--abstract Factory mode instances

Source: Internet
Author: User
1. Applicable environment

(mainly used in manufacturing a variety of products, software has a variety of skin, a variety of databases and other environments)

    • A system should not rely on the details of how a product class instance is created, composed, and expressed, which is important for all types of factory models.

    • There are more than one product family in the system, and only one of the product families is used at a time.

    • Products belonging to the same product family will be used together, and this constraint must be reflected in the design of the system.

    • The system provides a library of product classes, all products appear on the same interface, so that clients do not rely on the implementation of specific

2. Pattern definition

Abstract Factory Pattern: Provides an interface to create a series of related or interdependent objects without specifying their specific classes. Abstract Factory mode, also known as the kit mode, belongs to the object creation mode.

3. Pattern structure

The abstract factory pattern contains the following roles:

    • Abstractfactory: Abstract Factory

    • Concretefactory: Specific Factory

    • Abstractproduct: Abstract Products

    • Product: Specific Products

In order to understand the factory method pattern more clearly, two concepts need to be introduced first:

    • Product Hierarchy Structure: Product hierarchy structure is the product's inheritance structure, such as an abstract class is a television, its sub-category has Haier TV, Hisense TV, TCL TV, the abstract TV and the specific brand of television constitute a product hierarchy structure, abstract TV is the parent class, and the specific brand of the TV is its sub-category.

    • Product family: In the abstract factory model, product family refers to the production of the same factory, located in different product grade structure of a group of products, such as Haier Electric factory production of Haier TV, Haier refrigerator, Haier TV is located in the TV product grade structure, Haier Refrigerator is located in the refrigerator product grade structure.

4. Code

Process interface

Interface Iflow    {        irxalign createrxalign ();        Idispensing createdispensing ();    } Class Flowa:iflow    {public        irxalign createrxalign ()        {            return new Rxaligna ();        Public idispensing createdispensing ()        {            return new Dispensinga ();        }    } Class Flowb:iflow    {public        irxalign createrxalign ()        {            return new RXALIGNB ();        Public idispensing createdispensing ()        {            return new dispensingb ();        }    }

Coupling interface

Interface Irxalign {event Locationchange locchange;        Int[] Ropulse {set; get;}        Int[] Fipulse {set; get;}        Int[] Romaxstep {set; get;}        Double[] Rorestarget {set; get;}        Double[] TxP {set; get;}        Double[] Resmin {set; get;}        Double[] Resmax {set; get;}        Coordinate location {set; get;}        void Loadpara (string PN);        void GoHome ();        void Start ();    void Stop ();        }class rxaligna:irxalign {private Controlcard card;        Private QSFP28 product;        Private double Resmax, resmin, RES;        Private double[] Txpower; Public Rxaligna () {this.            Resmax = 1.0; This.        Resmin = 0.4;                } public bool Configpara () {try {this.card = new Controlcard ();                This.product = new QSFP28 ();            return true;      } catch {return false;      }} public void GoHome () {//QSFP28 go home} public void Start ()            {//QSFP28 start} public void Stop () {card = null;        Product = NULL; }        ...    }         Class Rxalignb:irxalign {private Controlcard card;         Private CFP4 product;         Private double Resmax, resmin, RES;         Private double[] Txpower; Public RXALIGNB () {this.             Resmax = 1.0; This.        Resmin = 0.4;                 } public bool Configpara () {try {this.card = new Controlcard ();                 This.product = new CFP4 ();            return true;            } catch {return false;            }} public void GoHome () {//CFP4 go home} public void Start () {    CFP4 start} public void Stop ()    {card = null;        Product = NULL; }        ...    }

Dispensing interface

Interface idispensing    {        //code    }class dispensinga:idispensing    {        //code    }class dispensingb : idispensing    {        //code    }

Main thread Call

flow = new Flowa (); align = flow. Createrxalign (); align. Loadpara (this.comboBoxPN.Text);d Ispens = flow. Createdispensing ();d Ispens.//code ...

The above is from 0 self-taught c#09--abstract Factory mode instance content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Related Article

    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.