abstract:<?php interface Message{public function seed();}class SeedEmail implements Message{ public function seed() { return
<?php
interface Message{public function seed();}
class SeedEmail implements Message{ public function seed() { return 'seed email'; } }
class SeedSMS implements Message{ public function seed() { return 'seed sms'; } }
class Order{ protected $messager = ''; function __construct(Message $message) { $this->messager = $message; } public function seed_msg() { return $this->messager->seed(); }}
//我们需要发送邮件的时候
$message = new SeedEmail();
//将邮件发送对象作为参数传递给Order
$Order = new Order($message);
$Order->seed_msg();
//我们需要发送短信的时候
$message = new SeedSMS();
$Order = new Order($message);
$Order->seed_msg();
Correcting teacher:查无此人Correction time:2020-02-27 15:33:10
Teacher's summary:完成的不错。依赖注入现在很流行,多了解。继续加油