示例#1
0
<?php

class MyObject
{
}
class MyFactory
{
    public static function factory()
    {
        return new MyObject();
    }
}
$instance = MyFactory::factory();
示例#2
0
    public function __construct()
    {
    }
    public function test()
    {
        echo "Test is YexuanGuo";
    }
}
class MyFactory
{
    public static function factory()
    {
        return new MyObject();
    }
}
$myobj = MyFactory::factory();
$myobj->test();
//观察者模式
class Subject implements SplSubject
{
    private $observers = array();
    //初始化变量为空数组,用于存放观察者对象.
    public function attach(SplObserver $observer)
    {
        if (!in_array($observer, $this->observers)) {
            $this->observers[] = $observer;
        }
    }
    public function detach(SplObserver $observer)
    {
        if (flase != ($index = array_search($observer, $this->observers))) {