<?php
//抽象策略类
abstract class baseAgent
{
abstract function PrintPage();
}
//具体策略:今天走路上班
class run extends baseAgent
{
function PrintPage()
{
return '今天走路上班';
}
}
//具体策略:今天开车上班
class car extends baseAgent
{
function PrintPage()
{
return '今天开车上班';
}
}
//具体策略角色
class Me
{
public function GoWork($object)
{
return $object->PrintPage ();
}
}
$m = new Me ();//我
$how_to_work = new car ();//用什么方式去上班
echo $m->GoWork ( $how_to_work );
$how_to_work = new run ();//用什么方式去上班
echo $m->GoWork ( $how_to_work );
?>