策略模式
// 策略模式 interface people { function say(); function paly(); } class Children implements people { function say() { echo "小孩子"; } function paly() { echo "跑跑跳跳"; } } class Man implements people { function say() { echo '男人'; } function paly() { echo '打游戏'; } } class WoMan implements people { function say() { echo '女人'; } function paly() { echo '逛街'; } } class Page { function index() { $this->type->say(); $this->type->paly(); } function setType( $type ) { $this->type = $type; } } $p = new Page(); $type = $_GET['type']; switch ($type) { case 1: $peopleType = new Children(); break; case 2: $peopleType = new Man(); break; case 3: $peopleType = new WoMan(); break; } $p->setType( $peopleType ); $p->index();