亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

依賴(lài)注入案例

original 2019-04-10 12:40:57 214
abstrait:class Father{     public function output(){     return "hello world";     }     } //
class Father{
    public function output(){
    return "hello world";
    }
    }

//使用構(gòu)造方法實(shí)現(xiàn)依賴(lài)注入
class Son{
    private $father = null;//制造容器來(lái)儲(chǔ)存
    public function __construct(Father $father)
    {
        $this -> father = $father;//把大類(lèi)傳入到小類(lèi)中保存起來(lái)了
        }
    public function getInfo()
    {
        return $this->father->output();
        }
        
        
 //在函數(shù)中進(jìn)行使用
 $father = new Father;
 $son = new Son($father);
 
 echo $son->output();


Professeur correcteur:天蓬老師Temps de correction:2019-04-10 13:28:48
Résumé du professeur:依賴(lài)注入, 簡(jiǎn)單的講, 就是把外部對(duì)象通過(guò)方法參數(shù)的形式傳入, 而不是方法中直接實(shí)例化, 以提升方法的獨(dú)立性

Notes de version

Entrées populaires