Home  >  Article  >  php教程  >  PHP高级对象构建工厂模式的使用

PHP高级对象构建工厂模式的使用

WBOY
WBOYOriginal
2016-06-13 10:47:19971browse

abstract class prModel {                             //产品模型 
    abstract function link(); 

  
class webLink extends prModel{                      //实例一个产品 
    public function link(){ 
        echo "www.2cto.com
    } 

  
class gongchang {                                  //工厂 
    static public function createLink (){ 
        return new webLink(); 
    } 

   
$weblink=gongchang::createLink();                 //通过工厂制造一个对象 
$weblink->link();                                 //输出www.xxx.com
?> 

摘自 chaojie2009的专栏

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn