简单的一个php工厂模式代码-PHP源码
1. [PHP]代码
radius = $radius; } public function getArea() { return $this->radius * $this->radius * pi(); } } class Square { private $side = 0; public function __construct($side) { $this->side = $side; } public function getArea() { return $this->side * $this->side; } } $shape = Shape::getShape('circle', 10); echo $shape->getArea(); echo "\n"; $shape = Shape::getShape('square', 2); echo $shape->getArea(); echo "\n";
PHP之友评论