Single Case : Single instance. Design a class, there are only one object, this design pattern is called a singleton mode!
Role : A single case design, is applicable to the use of an object can complete all business logic of the class, so that a class as long as the instantiation can complete all the business logic, thereby saving resources space !
Class Mydemo {
Private static $instance;
Private Function __construct ($p 1) {
}
Public static function getinstance($p 1) {
if (! (Self:: $instance instanceof Self)) {
Not instantiated.
Self:: $instance = new self ($p 1);
}
Return self:: $instance;
}
Private Function __clone () {
}
}
$demo 1 = mydemo::getinstance ($a);
$demo 2 = mydemo::getinstance ($a);
This article is from the "Linux Warden" blog, so be sure to keep this source http://sswqzx.blog.51cto.com/2494644/1964702
PHP Single-instance mode