Blogger Information
Blog 9
fans 0
comment 0
visits 5004
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
5月22作业
张凯的博客
Original
395 people have browsed it
<?php

/**
 * @Author: zhangkai
 * @Date:   2018-05-23 17:46:08
 * @Last Modified by:   owlcity
 * @Last Modified time: 2018-05-23 19:14:12
 */
/**
 * controller 
 *     功能:
 *         类名与文件名大小写保持一致,首字母大写,采用驼峰式命名
 *         处理应用程序用户交互部分,控制器负责从视图读取数据控制用户输入并向前端模版发送数据
 *     用法:
 *         1 参数绑定
 *         2 跳转和重定向
 * request
 *     功能:求对象由think\Request类负责,在很多场合下并不需要实例化调用,通常使用依赖注入
 *     用法:
 *     构造方法:
 *     普通方法:
 */

// 依赖注入
class Girl {
    public function work(){
        return "会做饭";
    }
}
// 构造方法注入
class Boy{
    private $girl = null;
    public function __construct(Girl $girl){
        $this->xx = $girl;
    }

    public function getInfo(){
        return '我的'.$this->xx->work();
    }

}
// 操作方法注入
class Boy2 {
    public function buy(Girl $lady){
        return '爱好'.$lady->work();
    }
}
$ss = new Girl;
$boy = new Boy($ss);
echo $boy->getInfo();
echo "<hr>";
$boy2 = new Boy2;
echo $boy2->buy($ss);


Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post