Example #1
0
    }
    public function __get($object)
    {
        return $this->{$object};
    }
    public function cost()
    {
        return $this->_strategy->cost($this);
    }
    public function type()
    {
        return $this->_strategy->type($this);
    }
}
class Arts extends Lesson
{
    protected $discount = 0.75;
    protected $type = "文科";
}
class Science extends Lesson
{
    protected $discount = 0.5;
    protected $type = "理科";
}
//应用
$arts = new Arts(6, new Math());
echo $arts->type() . $arts->cost();
echo "<br>";
$science = new Science(6, new Math());
echo $science->type() . $science->cost();