苗火 Nicholas
[PHP]An example of product mode
2015-11-12 萧


/* Here is an example of Product mode */



interface iProduct{


        public function realCreate();

}

class Product1{

        public function action(){

                echo " here is product 1";

        }

}

class Product2{

        public function action(){

                echo "this is product 2";

        }

}

class Product1Creator implements iProduct{

        public $id;

        public function realCreate(){

                return new Product1();

        }

}

class Product2Creator implements iProduct{

        public $id;

        public function realCreate(){

                return new Product2();

        }

}

class ProductFactory{

        public function create($what){

                $create = $what."Creator";

                return $create = new $create();

        }

}

$create = new ProductFactory();

$instance = $create->create("Product1");

$instance->id = 11;

$instance->realCreate()->action();
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容