set() public method

public set ( $colleague1, $colleague2 )
Ejemplo n.º 1
0
        } else {
            $this->_colleague2->notify($message);
        }
    }
    public function set($colleague1, $colleague2)
    {
        $this->_colleague1 = $colleague1;
        $this->_colleague2 = $colleague2;
    }
}
//Colleague1 Colleague2等各各具体同事类
class Colleague1 extends Colleague
{
    public function notify($message)
    {
        echo "Colleague1 Message is : " . $message . "\n";
    }
}
class Colleague2 extends Colleague
{
    public function notify($message)
    {
        echo "Colleague2 Message is : " . $message . "\n";
    }
}
$objMediator = new ConcreteMediator();
$objC1 = new Colleague1($objMediator);
$objC2 = new Colleague2($objMediator);
$objMediator->set($objC1, $objC2);
$objC1->send("to c2 from c1");
$objC2->send("to c1 from c2");