C # Abstract Factory mode

Source: Internet
Author: User

Think of the factory class creation method, here is an example written many years ago

1, provides a property for external access

2, the constructor initializes the property

3, create a subclass factory to inherit the properties of the implemented business class

  Public Abstract classBllfactory { Public StaticBllfactory Instance {Get;Private Set; } Staticbllfactory () {stringTypeName = configurationmanager.appsettings["BLL"];//The value of the BLL in the configuration file is HomefactoryType t = Type.GetType (TypeName,true,true); Objectobj =activator.createinstance (t); Instance=(bllfactory) obj; }        //interface of the user Management module business         Public AbstractIUSERBLL USERBLL {Get; } //interfaces for other module services         Public AbstractIOTHERBLL OTHERBLL {Get; } //....}

4,IUSERBLL Interface Implementation

     Public InterfaceIUSERBLL {/// <summary>        ///Account Registration/// </summary>        /// <param name= "user" >User basic Information</param>        /// <returns>whether the registration was successful</returns>        BOOLRegister (userdto user); /// <summary>        ///Account Login/// </summary>        /// <param name= "user" >Account/Password</param>        /// <param name= "ds" >User basic Information</param>        /// <returns>whether the login was successful</returns>                BOOLLogin (userdto user,refDataTable DT); }

5, sub-class factory Homefactory implementation

 Public classHomefactory:bllfactory { Public OverrideIUSERBLL USERBLL {Get             {                 return NewUSERBLL (); }        }         Public OverrideIOTHERBLL OTHERBLL {Get             {                 return NewOTHERBLL (); }        }        //...}

6,USERBLL implementation of IUSERBLL interface method

    Publicclass  userbll:iuserbll    {        #region IUSERBLL member        BOOL  iuserbll.register (userdto user)        {             // Code implementation logic         }         boolref  DataTable dt)        {             // Code implementation Logic         }         #endregion     }

7,IOTHERBLL,OTHERBLL can refer to the above IUSERBLL,USERBLL implementation

The significance of this implementation is that the configuration file can be flexibly used in different bllfactory implementation of the factory, like a factory and B factory they all produce bicycles, but a factory and B factory use of accessories and assembly method is not the same

And our business logic might be a factory using SQL Server database, while the B factory uses Oracle database, but can achieve the need for business data

8, calling method

BOOL IsOK = BLLFactory.Instance.UserDLL.Register (userdto);

C # Abstract 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.