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.