如何将一个工厂模式代码改写为长尾词?

2026-04-05 14:421阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计141个文字,预计阅读时间需要1分钟。

如何将一个工厂模式代码改写为长尾词?

php

<?php // factory pattern class Shape { static public function getShape($type, $dimension) { if ($type && $dimension) { switch($type) { case 'circle': return new Circle($dimension); break; case 'square': return new Square($dimension); break; default: throw new Exception("Unrecognized shape"); break; } } } } class Circle { private $radius = 0; public function __construct($radius) { $this->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";

如何将一个工厂模式代码改写为长尾词?

本文共计141个文字,预计阅读时间需要1分钟。

如何将一个工厂模式代码改写为长尾词?

php

<?php // factory pattern class Shape { static public function getShape($type, $dimension) { if ($type && $dimension) { switch($type) { case 'circle': return new Circle($dimension); break; case 'square': return new Square($dimension); break; default: throw new Exception("Unrecognized shape"); break; } } } } class Circle { private $radius = 0; public function __construct($radius) { $this->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";

如何将一个工厂模式代码改写为长尾词?