示例#1
0
 public function testVisitor()
 {
     $visitor = new PriceItemVisitor();
     $item = new BookItem($name = "Im Westen nichts Neues, Erich Maria Remarque", $price = 22.5);
     $price = $item->accept($visitor);
     $this->assertEquals(17.5, $price);
     $item = new FruitItem($name = "apple", $pricePerKg = 1.5, $weight = 2);
     $price = $item->accept($visitor);
     $this->assertEquals(3.0, $price);
 }
示例#2
0
 public function visitFruit(Fruit $fruit)
 {
     return $fruit->getPricePerKg() * $fruit->getWeight();
 }