Design Mode C ++ study note 4 (Multition multi-sample mode)

Source: Internet
Author: User

The multi-sample mode is not mentioned in the GOF pattern design, but it is actually used in actual work. For more details, refer to the original author's blog: cbf4life.cnblogs.com.

4. Explanation

Main (), customer

Omitted

Note: similar to Singleton, Singleton has a limited number of Singleton instances. If there is no limit on the number of instances generated, there are not multiple instances, and there is no difference between them and common classes.

For example, a program has been developed to send files from the server to the client using UDP protocol. The client uses the TCP protocol to connect to the server. The server accepts the connection and generates an instance of FileService that transfers files to the client. Each client connection generates an instance, but multiple connection requests from the same client share a FileService instance. Theoretically, the number of FileService instances depends on the number of clients connected to the service. Because it is an internal enterprise system, the number of connections here is limited, and there is no unlimited user connection on the wide area network. I think this is a special Singleton mode. You can save the instance in std: map and use the string consisting of the Client IP address and Port as the key value.

Class Diagram skipped.

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.