The example in this article describes the Java single case pattern, which is a very important concept in Java programming. Share to everyone for your reference. The specific analysis is as follows:
The so-called list mode is the entire application process to provide only a single instance of the outside world, that is, the application of only one instance, so you do not have to repeatedly create instances . Then, according to his requirements, look at one of the simplest examples of the code in the single example pattern:
public class Singleton {
private static Singleton single = new Singleton ();
Private Singleton () {
} public
static Singleton getsingletoninstance ()}
Through this code, we find that to implement this instance of the Singleton class, we have to pass the constructor, but his constructor is private, so it is impossible to implement his instantiation in other classes, but you can use the Getsingletoninstance method, Can return an instance single because he is a static function of public and can be called by another class. This is a simple single case pattern. Of course, you can also put a single statement in the Getsingletoninstance method to achieve.
Summarize the characteristics of the single example pattern:
1. The construction method is private decorated .
2. There is a private instance of static application .
3. there is a static public method that returns an instance of the class .
In fact, these three characteristics are entirely determined by the requirement of a single case model.
I hope this article will help you with your study of Java programming.