10分钟快速理解依赖注入
2016-12-13 16:39
477 查看
https://www.phpxy.com/article/200.html
<?php interface travelinterface { public function __construct($speed, $distance); public function run(); } abstarct class travel implements travelinterface { protect $speed; //最高时速 protect $distance; //最远路程 public function __construct($speed, $distance) { $this->speed = $speed; $this->distance = $distance; } } class drive extends travel { public function run() { echo '自驾游'; } } class walk extends travel { public function run() { echo '徒步旅行'; } } class human { protect $travel; public function __construct(travel $travel) { $this->travel = $travel; } // public function __construct() // { // $this->travel = new drive(60,1000); // } public function traveling() { $this->traveling->run(); } } $travel = new drive(60, 1000); $xiaoming = new human(); $xiaoming->traveling(); //配置 $config = [ "travel" => drive::class, ]; $travel = new $config["travel"](60,1000); $xiaoming = new human($travel); $xiaoming->traveling();
相关文章推荐
- 10分钟快速理解依赖注入
- 10分钟快速理解依赖注入
- 10分钟快速理解依赖注入
- 10分钟快速理解依赖注入
- 10分钟快速理解依赖注入
- 总结: 十分钟快速理解 Spring DI 依赖注入
- 十分钟快速理解依赖注入
- 10分钟理解依赖注入
- 代码的演化-DI(理解依赖注入di,控制反转ioc)
- Spring 学习总结(一)依赖注入的理解
- 我对IOC控制反转,依赖注入原理的理解
- 理解依赖注入(IOC)和学习Unity
- 对于依赖注入的理解
- 深入理解依赖注入
- 深度理解依赖注入(Dependence Injection)
- 依赖注入的理解
- [转] 深度理解依赖注入(Dependence Injection): Inversion of Control Containers and the Dependency Injection pattern
- 深度理解依赖注入(Dependence Injection)
- 依赖注入容器Unity Application Block快速入门(整理更新版,非原创)
- 对依赖注入的一些理解