Home  >  Article  >  php教程  >  星际争霸之php原型模式

星际争霸之php原型模式

WBOY
WBOYOriginal
2016-06-07 17:23:051068browse

我们一般用new来新增对象,不过很多时候新增一个对象需要一些工作。而星际里面往往会新增某些类的大量的对象,比如新增很多机枪兵和龙骑。

待解决的问题:我们能否减少new的使用,同时避免需要新增对象的时候,了解对象的类名。

思路:php5提供了克隆方法,我们可以新增一个对象,然后每次需要新增和她同类的对象,克隆他就可以了。

原型(Prototype)模式示例:

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn