The content of this article is about the prototype mode of PHP design pattern, which has certain reference value. Now I share it with everyone. Friends in need can refer to it
PrototypeIt’s not difficult to understand.
To sum up, it is to create objects through a cloning method to save the complexity of creating objects.
It can be mainly used to prevent a lot of code redundancy caused by repeatedly creating objects.
The recording code is as follows:
Copy after login
weapon = "琉璃琴"; // 添加武器 // 第二次通过克隆一号英雄 得到二号英雄 $hero2 = $hero1->Cloned(); $hero1->Create(); echo "=>{$hero1->weapon}
"; // 克隆 会将类里面的函数和变量复制一份 $hero2->Create(); echo "=>{$hero2->weapon}
";
##The output result is:
The hero has been The creation is completed, holding the Liuli Qin in hand=>Liu Li Qin
The hero has been created, holding the Liu Li Qin
PHP design pattern singleton pattern
PHP design pattern abstract factory factory method of PHP design patternThe above is the detailed content of PHP Design Patterns Prototype Pattern. For more information, please follow other related articles on the PHP Chinese website!