我一生没做坏事,为何这样?
不是我自身的,却是我需要的,都是我所依赖的。一切需要外部提供的,都是需要进行依赖注入的。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| <?php
interface Girl {
}
class LoliGril implements Girl { public function __construct() { echo "LoliGril girl friend"; } public function make() { echo "love LoliGril "; } }
class Vixen implements Girl { public function __construct() { echo "Vixen girl friend"; } public function make() { echo "love Vixen "; } }
class Boy { protected $girl;
public function __construct(Girl $girl) { $this->girl = $girl; }
public function yoyo() { $this->girl->make(); } }
$loliGirl = new LoliGril();
$boy = new Boy($loliGirl); $boy->yoyo();
|