继续练
<?php /* The factory method pattern deals with the problem of creating objects without having to specify the exact class of the object that will be created. */ interface Product { public function getType(); } interface ProductFactory { public function makeProduct(); } class SimpleProduct implements Product { public function getType() { return 'SimpleProduct'; } } class SimpleProductFactory implements ProductFactory { public function makeProduct() { return new SimpleProduct(); } } //Client $factory = new SimpleProductFactory(); $product = $factory->makeProduct(); echo $product->getType(); ?>
输出
SimpleProduct