php设计模式-延迟初始化(Lazy Initialization)
来源:互联网 发布:腾讯传奇霸业羽毛数据 编辑:程序博客网 时间:2024/06/13 03:11
转自:https://segmentfault.com/a/1190000003817321
对于某个变量的延迟初始化也是常常被用到的,对于一个类而言往往并不知道它的哪个功能会被用到,而部分功能往往是仅仅被需要使用一次。
<?phpinterface Product { public function getName();}class Factory { protected $firstProduct; protected $secondProduct; public function getFirstProduct() { if (!$this->firstProduct) { $this->firstProduct = new FirstProduct(); } return $this->firstProduct; } public function getSecondProduct() { if (!$this->secondProduct) { $this->secondProduct = new SecondProduct(); } return $this->secondProduct; }}class FirstProduct implements Product { public function getName() { return 'The first product'; }}class SecondProduct implements Product { public function getName() { return 'Second product'; }}$factory = new Factory();print_r($factory->getFirstProduct()->getName());// The first productprint_r($factory->getSecondProduct()->getName());// Second productprint_r($factory->getFirstProduct()->getName());// The first product
阅读全文
0 0
- php设计模式-延迟初始化(Lazy Initialization)
- 大中型项目之软件设计方法-设计模式-延迟加载技术(Lazy initialization)
- Hibernate 中的 延迟初始化……Lazy Initialization
- Python延迟初始化(lazy property)
- Lazy Initialization and the DAO pattern with Hibernate and Spring(Spring 与Hibernate的延迟加载和Dao模式)
- Hibernate入门24 - 延迟初始 Lazy Initialization
- Lazy initialization holder class模式
- Lazy initialization holder class模式
- 惰性初始模式 Lazy Initialization
- Lazy initialization holder class模式
- spring的延迟初始化bean (default-lazy-init 与 lazy-init )
- spring的延迟初始化bean (default-lazy-init 与 lazy-init )
- c# - Lazy<T> 延迟初始化对象
- C#性能优化:延迟初始化Lazy<T>
- Scala中的延迟初始化(Lazy vals)
- Lazy initialization
- Lazy Initialization
- hibernate lazy(延迟加载)
- Python logging模块详解
- Android Studio 真机调试出现 Unable to instantiate activity ComponentInfo的解决方案
- .Net MVC 导入导出Excel总结(三种导出Excel方法,一种导入Excel方法)
- [python]在shell中运行
- RealSense in ubuntu
- php设计模式-延迟初始化(Lazy Initialization)
- Android——实现m3u8视频缓存
- 静态链接库与动态链接库----C/C++
- 定点化
- 12串口通信的定义-2
- java中的代码点和代码单元
- tomcat启动时出现了Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]等错误
- Qrcode生成二维码工具类
- string::assign函数