Singleton
Singleton只需把一个类的构造函数变成私有的,并且在其中增加相应的静态函数和变量,就可以把这个类变为singleton。
public class NodeFormatExtractor { private static NodeFormatExtractor sExtractorInstance; private NodeFormatExtractor() { } public static synchronized NodeFormatExtractor getInstance(Context context) { if (sExtractorInstance == null) { sExtractorInstance = new NodeFormatExtractor(); } return sExtractorInstance; } }

浙公网安备 33010602011771号