<?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();