标签:php div ext bre default style func 模式 turn
<?php
# 简单工厂
abstract class mycoach
{
public function __construct(){}
}
class cultivatecpc extends mycoach{
public function __construct(){
echo "把陈培昌培养为搏击教练"."\n";
}
}
class cultivatecj extends mycoach{
public function __construct(){
echo "把程劲培养为搏击教练"."\n";
}
}
class martialclub
{
public function cultivate($name)
{
switch($name){
case ‘cj‘:
return new cultivatecj();
case ‘cpc‘:
return new cultivatecpc();
default:
echo ‘培养一个小教练‘."\n";
break;
}
return null;
}
}
class clubmaster{
public function cultivate()
{
$myclub = new martialclub();
$myclub->cultivate(‘cj‘);
$myclub = new martialclub();
$myclub->cultivate(‘cpc‘);
}
}
$mymaster = new clubmaster();
$mymaster->cultivate();
输出结果:
把程劲培养为搏击教练
把陈培昌培养为搏击教练
标签:php div ext bre default style func 模式 turn
原文地址:https://www.cnblogs.com/saintdingspage/p/11330426.html