2019-04-10 20:22:13 +02:00
|
|
|
class Circle {
|
2019-05-17 08:40:41 +02:00
|
|
|
public void draw() {
|
2019-04-10 20:22:13 +02:00
|
|
|
print("Circle\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Square {
|
2019-05-17 08:40:41 +02:00
|
|
|
public void draw() {
|
2019-04-10 20:22:13 +02:00
|
|
|
print("Square\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Program {
|
|
|
|
|
|
|
|
object ShapeFactoryMethod(string $shape) {
|
|
|
|
switch ($shape) {
|
|
|
|
case "Circle":
|
|
|
|
return new Circle();
|
|
|
|
case "Square":
|
|
|
|
return new Square();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-17 08:40:41 +02:00
|
|
|
public void main() {
|
2019-04-10 20:22:13 +02:00
|
|
|
$this->ShapeFactoryMethod("Circle")->draw();
|
|
|
|
$this->ShapeFactoryMethod("Square")->draw();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|