2010年5月16日 星期日

Prototype Pattern -- Load User Define Library

function testUnit_CreateCustom()
    {
        $Custom = $this->cucustom->MyClone();
        echo $this->unit->run($Custom != NULL, "is_TRUE", "Create Custom");
        
        if( $Custom == NULL )
            return;
        
        $Custom->Init("Eric", "1234567", "高興路");
        echo $this->unit->run($Custom->name, "Eric", "name");
        echo $this->unit->run($Custom->tel, "1234567", "tel");
        echo $this->unit->run($Custom->address, "高興路", "address");
        
    }

class cucustom {

    var $name;
    var $tel;
    var $address;

    function cucustom($name = "", $tel = "", $address = "")
    {
        $this->Init($name, $tel, $address);
    }

    function MyClone()
    {
        return new cucustom;
    }

    function Init($name = "", $tel = "", $address = "")
    {
        $this->name = $name;
        $this->tel = $tel;
        $this->address = $address;
    }
}

1 則留言:

  1. 使用CodeIgniter 載入的 class 只會有一份實體, 要在多new 就麻煩了, 在這裡使用 MyClone 隨手的解決這個小問題!

    回覆刪除