php设计模式-原型模式(Prototype)
来源:互联网 发布:vue.js权威指南 微盘 编辑:程序博客网 时间:2024/06/14 11:56
转自:https://segmentfault.com/a/1190000003817321
有些时候,部分对象需要被初始化多次。而特别是在如果初始化需要耗费大量时间与资源的时候进行预初始化并且存储下这些对象。
<?phpinterface Product {}class Factory { private $product; public function __construct(Product $product) { $this->product = $product; } public function getProduct() { return clone $this->product; }}class SomeProduct implements Product { public $name;}$prototypeFactory = new Factory(new SomeProduct());$firstProduct = $prototypeFactory->getProduct();$firstProduct->name = 'The first product';$secondProduct = $prototypeFactory->getProduct();$secondProduct->name = 'Second product';print_r($firstProduct->name);// The first productprint_r($secondProduct->name);// Second product
阅读全文
0 0
- php设计模式-原型模式(Prototype)
- 原型(Prototype)设计模式
- 设计模式-原型设计模式(Prototype)
- 设计模式-原型设计模式(Prototype)
- PHP Prototype(原型)模式
- 设计模式 原型Prototype
- prototype(原型设计模式)
- 设计模式--Prototype(原型)
- Prototype(原型)设计模式
- 设计模式-prototype原型
- 设计模式之原型模式(Prototype)
- 设计模式--原型模式(Prototype)
- 设计模式之原型模式(Prototype)
- 设计模式-原型模式(Prototype Pattern)
- 设计模式---原型模式(Prototype)
- 设计模式 (五)原型模式(Prototype)
- 设计模式 (五)原型模式(Prototype)
- 设计模式 (五)原型模式(Prototype)
- POJ
- iText制作PDF文件 学习笔记 (三)
- 关于listview多条目的实现
- 简单工厂模式
- 数据库开发技术 大数据产业和产品链条
- php设计模式-原型模式(Prototype)
- Java反射
- php中正则表达式详解
- request初步和获取表单数据
- 20171009
- 简单理解c语言——‘\0’ ,‘0’, “0” ,0之间的区别
- Ubuntu环境下的nwjs安装使用
- SpringBoot 使用@Aspect进行日志管理(基于反射代理模式+注解Log)
- 【超详细图文教程】用SpringBoot+Maven搭建SSM框架