<?php
class NorthCook {
public function fan() { return '面条'; }public function cai() {
return '炒菜'; }public function tang() {
return '蛋花汤'; }}class SouthCook {
public function fan() { return '米饭'; }public function cai() {
return '烧菜+奶油'; }public function tang() {
return '海鲜汤'; }}class FD {
protected $fanCreateor = null; protected $caiCreateor = null; protected $tangCreateor = null;public function __construct($f,$c,$t) {
$this->fanCreateor = $f; $this->caiCreateor = $c; $this->tangCreateor = $t; }public function createFan() {
return $this->fanCreateor->fan(); }public function createCai() {
return $this->caiCreateor->cai(); }public function createTang() {
return $this->tangCreateor->tang(); }} $fd = new FD(new NorthCook() , new NorthCook() , new SouthCook);echo $fd->createFan() , "<br>";
echo $fd->createTang() , "<br />";
?>