#模式设计
# #1, default mode (also called default mode)
# # #1.1-There is a monk interface, Monk interface methods have Chizhai, meditation, chanting, martial arts, and there is a LU Zhishen to achieve this interface, but he did not want to implement all the methods in the interface, he only want to use the monk interface in the martial arts method. What about this time?
# # #1.2-Solution: Find an Intermediate class, this class can be an abstract class, or it can be a concrete class, let this class to implement the Monk interface, the middle class for LU Zhishen LU zhishen service, Lu Zhishen need what method, it will implement what method, the other method without tube, and then Lu Zhishen to inherit this intermediate class, After inheritance, only use martial arts this method can be
# # #1.3-Specific implementation:
Lu Zhishen Inheritance —————— > Intermediate class implementation —————— > Monk interface
# #2, Singleton mode
# # #1, lazy-style features:
There can be only one instance (static constructor method private)
Instantiate your own unique instance (self-declared static private)
Promote yourself (externally provide new own public static method)
Private Singleton () {};
private static Singleton Singleton=null;
public static Getsingleton () {
if (singleton==null) {
Singleton=new Singleton ();
}
return singleton;
}
# # #2, a Hungry man single-case mode
Private Singleton () {}
Private static final Singleton single = new Singleton1 ();
Static Factory method
public static Singleton1 getinstance () {
return single;
}
Default mode and singleton mode for Java