Esempio n. 1
0
    {
        $this->btd = $btd_in;
    }
    function starTitle()
    {
        $this->btd->title = Str_replace(" ", "*", $this->btd->title);
    }
}
echo tagins("html");
echo tagins("head");
echo tagins("/head");
echo tagins("body");
echo "BEGIN TESTING DECORATOR PATTERN";
echo tagins("br") . tagins("br");
$patternBook = new Book("Gamma, Helm, Johnson, and Vlissides", "Design Patterns");
$decorator = new BookTitleDecorator($patternBook);
$starDecorator = new BookTitleStarDecorator($decorator);
$exclaimDecorator = new BookTitleExclaimDecorator($decorator);
echo "showing title : " . tagins("br");
echo $decorator->showTitle();
echo tagins("br") . tagins("br");
echo "showing title after two exclaims added : " . tagins("br");
$exclaimDecorator->exclaimTitle();
$exclaimDecorator->exclaimTitle();
echo $decorator->showTitle();
echo tagins("br") . tagins("br");
echo "showing title after star added : " . tagins("br");
$starDecorator->starTitle();
echo $decorator->showTitle();
echo tagins("br") . tagins("br");
echo "showing title after reset: " . tagins("br");
Esempio n. 2
0
class BookTitleStarDecorator extends BookTitleDecorator
{
    private $btd;
    public function __construct(BookTitleDecorator $btd_in)
    {
        $this->btd = $btd_in;
    }
    function starTitle()
    {
        $this->btd->title = Str_replace(" ", "*", $this->btd->title);
    }
}
writeln('BEGIN TESTING DECORATOR PATTERN');
writeln('');
$patternBook = new Book('Gamma, Helm, Johnson, and Vlissides', 'Design Patterns');
$decorator = new BookTitleDecorator($patternBook);
$starDecorator = new BookTitleStarDecorator($decorator);
$exclaimDecorator = new BookTitleExclaimDecorator($decorator);
writeln('showing title : ');
writeln($decorator->showTitle());
writeln('');
writeln('showing title after two exclaims added : ');
$exclaimDecorator->exclaimTitle();
$exclaimDecorator->exclaimTitle();
writeln($decorator->showTitle());
writeln('');
writeln('showing title after star added : ');
$starDecorator->starTitle();
writeln($decorator->showTitle());
writeln('');
writeln('showing title after reset: ');