Beispiel #1
0
    }
    function getAuthor()
    {
        return $this->author;
    }
    function getTitle()
    {
        return $this->title;
    }
    function getAuthorAndTitle()
    {
        return $this->getTitle() . ' by ' . $this->getAuthor();
    }
}
define('BR', '<' . 'BR' . '>');
echo 'BEGIN TESTING STRATEGY PATTERN' . BR;
echo BR;
$book = new Book('PHP for Cats', 'Larry Truett');
$strategyContextC = new StrategyContext('C');
$strategyContextE = new StrategyContext('E');
$strategyContextS = new StrategyContext('S');
echo 'test 1 - show name context C' . BR;
echo $strategyContextC->showBookTitle($book);
echo BR . BR;
echo 'test 2 - show name context E' . BR;
echo $strategyContextE->showBookTitle($book);
echo BR . BR;
echo 'test 3 - show name context S' . BR;
echo $strategyContextS->showBookTitle($book);
echo BR . BR;
echo 'END TESTING STRATEGY PATTERN' . BR;
Beispiel #2
0
        return $this->author;
    }
    function getTitle()
    {
        return $this->title;
    }
    function getAuthorAndTitle()
    {
        return $this->getTitle() . ' by ' . $this->getAuthor();
    }
}
writeln('BEGIN TESTING STRATEGY PATTERN');
writeln('');
$book = new Book('PHP for Cats', 'Larry Truett');
$strategyContextC = new StrategyContext('C');
$strategyContextE = new StrategyContext('E');
$strategyContextS = new StrategyContext('S');
writeln('test 1 - show name context C');
writeln($strategyContextC->showBookTitle($book));
writeln('');
writeln('test 2 - show name context E');
writeln($strategyContextE->showBookTitle($book));
writeln('');
writeln('test 3 - show name context S');
writeln($strategyContextS->showBookTitle($book));
writeln('');
writeln('END TESTING STRATEGY PATTERN');
function writeln($line_in)
{
    echo $line_in . "<br/>";
}