批改状态:未批改
老师批语:
请求对象:指用户需要查看或者处理的东西并以URL的形式 发送。
控制器:相当于一计算机的处理器 将用户的提交的数据收集处理并以一定的形式反馈与用户。
<?php
//依赖注入的俩种方法
//一、构造方法实现
class Method{
public function planA (){
return'用PHPstorm';
}
public function planB(){
return'用sublime';
}
}
class People{
private $tool=null;
public function __construct(Method $method)
{
$this->method=$method;
}
public function getMethod(){
return '小明喜欢'.$this->method->planA();
}
}
$method =new Method();
$people1= new People($method);
echo $people1->getMethod();
echo'<hr>';
//二、普通方法实现依赖注入
class People2{
public function getMethod(Method $method){
return '小明不擅长'.$method->planB();
}
}
$method =new Method();
$People2 =new People2();
echo $People2->getMethod($method);点击 "运行实例" 按钮查看在线实例

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号