StarCraft allows players to cheat. Of course, this is the time to compete with computers. Moreover, cheating has a special feature, such as rapid construction. unlimited energy is effective for all players (including computers). If cheating is disabled, the effects on all players will disappear at the same time. This means that if we take the cheating status as a class, we can only have one object. Problem to be solved: make sure that a class can only have one object. StarCraft allows players to cheat. Of course, this is the time to compete with computers. Moreover, cheating has a special feature, such as rapid construction. unlimited energy is effective for all players (including computers). If cheating is disabled, the effects on all players will disappear at the same time.
This means that if we take the cheating status as a class, we can only have one object.
Problem to be solved: make sure that a class can only have one object.
Idea: revoke the permissions of newly created objects, including new and clone. To prevent override of methods and members of the parent class by subclass, set the class to final. Use static members to save Unique objects
Single-piece mode example:
FastBuild =! $ This-> fastBuild; }}// Method for reading the effective state of the quick build. Use public to publicly call the public function getStatus () {return $ this-> fastBuild ;} // obtain the unique public function getInstance () {// if the object is not created, create it if (! Isset (self ::$ instance) {self ::$ instance = new cheat ();} return self ::$ instance ;} // use private to disable the private function of a new object other than this class.