PHP Code:--------------------------------------------------------------------------------
function FactoryMethod ($class _type)
{
Switch ($class _type)
{
Case "Foo":
$obj = new Myfoo ();
Break
Case "Bar":
$obj = new Mybar ();
Break
}
return $obj;
}
$object = FactoryMethod ("foo");
$object->method ()->method ()
$copy _of_object = $object->__clone ();
Class MyClass
{
function __destruct ()
{
...//Run destructor code
}
}
Delete $object;
Class Shape {
function __construct ()
{
Shape initialization code
...
}
...
};
Class Square extends Shape
{
function __construct ()
{
Parent::__construct ();
Square-specific Initialization code
...
}
...
};
Class Foo
{
Private $priv _var;
function Some_method (...)
{
$this->priv_var = ...; Zend wrote: $priv _var = ...; , I haven't tried.
}
};
Class Logger
{
static $m _instance = NULL;
function Instance ()
{
if (Logger:: $m _instance = = NULL)
{
Logger:: $m _instance = new Logger ();
}
Return Logger:: $m _instance;
}
function Log ()
{
...
}
};
$Logger = Logger::instance ();
$Logger->log (...);
Try
{
... code
if (failure)
{
throw new MyException ("Failure");
}
... code
}
catch ($exception)
{
... Handle exception
Throw $exception; Re-throw exception.
}
http://www.bkjia.com/PHPjc/631456.html www.bkjia.com true http://www.bkjia.com/PHPjc/631456.html techarticle PHP Code:--------------------------------------------------------------------------------function FactoryMethod ($class _type) {switch ($class _type) {case "foo": $obj = new My ...