Php Singleton mode instance analysis, php Singleton mode application scenarios
Examples of the single-sample mode in php design mode, principles and skills of the single-sample mode in php, and the implementation method of the single-sample mode in php are learned through examples. Singleton mode (responsibility mode): an object (before learning the design mode, you must have a better understanding of object-oriented ideas) is only responsible for a specific task; Singleton class: 1. the constructor needs to mark as private (access control: prevents external code from using the new operator to create objects). the singleton class cannot be instantiated in other classes, it can only be instantiated by itself; 2. it has a static member variable for an instance that saves classes; 3. it has a public static method to access this instance (commonly used getInstance () the instanceof operator can be used to check whether the class has been instantiated) |