PHP Classes

File: test-spl.php

Recommend this page to a friend!
  Classes of Michal Vrchota   Observerable   test-spl.php   Download  
File: test-spl.php
Role: Example script
Content type: text/plain
Description: tutorial how to use observer
Class: Observerable
Implements the observerable design pattern
Author: By
Last change:
Date: 17 years ago
Size: 484 bytes
 

Contents

Class file image Download
<?php

$robots
= new Observerable();

class
KillingRobot implements SplObserver
{
    public function
update(SplSubject $subject)
    {
        echo
"kill all humans";
    }
}

class
WashingRobot implements SplObserver
{
    public function
update(SplSubject $subject)
    {
        echo
"wash all humans";
    }
}

$killing_robot = new KillingRobot();
$washing_robot = new WashingRobot();
$robots->addObserver($killing_robot);
$robots->addObserver($washing_robot);
$robots->notify();

?>