Step by step. NET Design Patterns learning notes 2. Abstract Factory)

Source: Internet
Author: User

Let's take a thread example to illustrate how the abstract factory works. we usually send and receive emails, so we can create a mail engine thread. definition: Abstract Factory mode is a creation mode. The above metaphor shows that the abstract factory is the thing that produces the same series of products, because these series of products are related. If they are mixed, problems may occur, therefore, it is uniformly created in the abstract factory. To add a new product series, you can add a factory subclass and a product subclass.

Let's look at a class chart.

In the figure, we can see that when the customer needs to obtain a series of products, they can directly create products using the corresponding factory subclass.

We have designed a mail sending thread instance:

First, create an interface ISaaSProcess. cs:

Html # viewSource "commandName =" viewSource "highlighterId =" highlighter_548602 "> view sourceprint?
/// <summary>
/// Call the interface Asynchronously
/// </summary>
public interface ISaaSProcess
{
    /// <summary>
    /// Start a thread task
    /// </summary>
    void StartProcess();
    /// <summary>
    /// Stop a thread task
    /// </summary>
    void StopProcess();
    /// <summary>
    /// Display the result
    /// </summary>
    /// <returns></returns>
    List<string> GetResult();
}

Then create a factory base class saasproccorner. cs:

View sourceprint?
public abstract class SaaSProcessBase : ISaaSProcess
    {
        /// <summary>
        /// Record the Log Content
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.