<?php
//PRODUCT
abstract class Product
{
abstract function getName();
}
class ProductOne extends Product
{
public function getName(){
echo "Product One";
}
}
class ProductTwo
{
public function getName(){
echo "Product Two";
}
}
//CREATOR
abstract class ProductCreator
{
abstract function getProduct();
}
class ProductOneCreator extends ProductCreator
{
public function getProduct(){
return new ProductOne();
}
}
class ProductTwoCreator extends ProductCreator
{
public function getProduct(){
return new ProductTwo();
}
}
$creator_one = new ProductOneCreator();
$product_one = $creator_one->getProduct();
$product_one = new ProductOne();
PD9waHAKCi8vUFJPRFVDVAphYnN0cmFjdCBjbGFzcyBQcm9kdWN0CnsKCWFic3RyYWN0IGZ1bmN0aW9uIGdldE5hbWUoKTsKfQoKY2xhc3MgUHJvZHVjdE9uZSBleHRlbmRzIFByb2R1Y3QKewoJcHVibGljIGZ1bmN0aW9uIGdldE5hbWUoKXsKCQllY2hvICJQcm9kdWN0IE9uZSI7Cgl9Cn0KCmNsYXNzIFByb2R1Y3RUd28KewoJcHVibGljIGZ1bmN0aW9uIGdldE5hbWUoKXsKCQllY2hvICJQcm9kdWN0IFR3byI7Cgl9Cn0KCi8vQ1JFQVRPUgphYnN0cmFjdCBjbGFzcyBQcm9kdWN0Q3JlYXRvcgp7CglhYnN0cmFjdCBmdW5jdGlvbiBnZXRQcm9kdWN0KCk7Cn0KCmNsYXNzIFByb2R1Y3RPbmVDcmVhdG9yIGV4dGVuZHMgUHJvZHVjdENyZWF0b3IKewkKCXB1YmxpYyBmdW5jdGlvbiBnZXRQcm9kdWN0KCl7CgkJcmV0dXJuIG5ldyBQcm9kdWN0T25lKCk7Cgl9Cn0KCmNsYXNzIFByb2R1Y3RUd29DcmVhdG9yIGV4dGVuZHMgUHJvZHVjdENyZWF0b3IKewoJcHVibGljIGZ1bmN0aW9uIGdldFByb2R1Y3QoKXsKCQlyZXR1cm4gbmV3IFByb2R1Y3RUd28oKTsKCX0KfQoKJGNyZWF0b3Jfb25lID0gbmV3IFByb2R1Y3RPbmVDcmVhdG9yKCk7CiRwcm9kdWN0X29uZSA9ICRjcmVhdG9yX29uZS0+Z2V0UHJvZHVjdCgpOwoKJHByb2R1Y3Rfb25lID0gbmV3IFByb2R1Y3RPbmUoKTs=