1<?PHP2 3 4 /*5 Design Patterns6 is an empirical summary of the code patterns in "Common tasks" in object-oriented programming. 7 It is not an object-oriented syntax, or concept. 8 corresponding to our previous "algorithm"--the idea of solving the problem. 9 Ten the so-called design pattern, is to solve some kind of problem code routines. One Different problems, different routines, also constitute a different design pattern. A - There are a number of design patterns. - the - single-case mode - in practical applications, some classes, which only need new "one object", are sufficient to accomplish the design goal of the class-to accomplish a specific task. - Then: + if a class is designed so that the class "can only get a corresponding object", then this class, called "Singleton Class", its new object is called "Singleton object". - + A at */ - //Design Patterns - classS { - Private Static $instance=NULL; - - //private constructs do not allow outside new objects in Private function__construct () { - to } + - //declares a static method to provide the outside world with a static method that can only be used to derive an object from the Public Static functiongetinstance () { * $ if(Empty(Self::$instance)) {//determine if a static variable is nullPanax NotoginsengSelf::$instance=NewSelf (); - returnSelf::$instance;//new Object If the variable is null the}Else{ + A returnSelf::$instance; the + } - $ } $}
PHP Single-instance mode