コード例 #1
0
ファイル: light_test.php プロジェクト: ymnl007/designpatterns
 public function testLight()
 {
     $lamp = new Light();
     $switchUp = new FlipUpCommand($lamp);
     $switchDown = new FlipDownCommand($lamp);
     $s = new Switcher();
     $this->assertEquals('The light is off', $s->storeAndExecute($switchDown));
     $this->assertEquals('The light is on', $s->storeAndExecute($switchUp));
 }
コード例 #2
0
<?php

require 'light.php';
$lamp = new Light();
$switchUp = new FlipUpCommand($lamp);
$switchDown = new FlipDownCommand($lamp);
$s = new Switcher();
$case = "off";
if ($case == "on") {
    echo $s->storeAndExecute($switchUp);
} else {
    echo $s->storeAndExecute($switchDown);
}