Java design pattern — singleton design pattern

/*Design pattern: an effective solution to the problem. In fact, it is a kind of thought. 1. Single case design mode. The problem to be solved is to ensure the object uniqueness of a class in memory. When the same configuration information object must be used for multiple programs, it is necessary to ensure the uniqueness of the object. How to ensure object uniqueness? 1. Other programs are not allowed to create this kind of object with new. 2. Create an instance of this class in this class. 3. Provide a method for other programs to obtain the object. Step 1: privatize the constructor of this class. 2. Create a class object in this class through new. 3. Define a public method to return the created object. The following four codes can be placed in one file or in different files.

The main function is in the singledemo. It is recommended to put it in the same file, so that it can run without changing the code*/

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>