Exemplo n.º 1
0
<?php

function __autoload($name)
{
    require_once "classes/{$name}.php";
}
$t = Timer::instance();
$t->newTimePoint('Begin of requuest');
VehicleFactory::create(VehicleFactory::TYPE_CAR)->move();
echo '<br />';
$t->newTimePoint('After "Car" creation');
VehicleFactory::create(VehicleFactory::TYPE_PLANE)->move();
echo '<br />';
$t->newTimePoint('After "Plane" creation');
$bookAdapter = new BookAdapter(new Book('Nikolay D.', 'It woluld be nice to have my own book :]'));
echo "{$bookAdapter->getAuthorAndTitle()}<br />";
$t->newTimePoint('Prepare library.');
$booksDb = array(new Book('A 1', 'T 1'), 1, new Book('A 1', 'T 2'), 2, new Book('A 2', 'T 1'), 3, new Book('A 3', 'T 1'), 4, new Book('A 3', 'T 2'), 5);
$library = new Library('FMI Library');
for ($i = 0; $i < count($booksDb); $i += 2) {
    $library->addBook($booksDb[$i], $booksDb[$i + 1]);
}
echo "Library content: total => {$library->getBooksCount()}, distinct => {$library->getDistinctBooksCount()}<br />";
$book = $booksDb[0];
$t->newTimePoint('Library - prepared, testing proxy implementation.');
echo 'Proxy test...<br />';
$proxy = new LibraryProxy($library);
if ($proxy->hasQuantityFor($book)) {
}
echo "{$book} is in the library.<br />";
$ticket = $proxy->lendBook($book);
Exemplo n.º 2
0
        return $this->author;
    }
    function getTitle()
    {
        return $this->title;
    }
}
class BookAdapter
{
    private $book;
    function __construct(SimpleBook $book_in)
    {
        $this->book = $book_in;
    }
    function getAuthorAndTitle()
    {
        return $this->book->getTitle() . ' by ' . $this->book->getAuthor();
    }
}
// client
writeln('BEGIN TESTING ADAPTER PATTERN');
writeln('');
$book = new SimpleBook("Gamma, Helm, Johnson, and Vlissides", "Design Patterns");
$bookAdapter = new BookAdapter($book);
writeln('Author and Title: ' . $bookAdapter->getAuthorAndTitle());
writeln('');
writeln('END TESTING ADAPTER PATTERN');
function writeln($line_in)
{
    echo $line_in . "<br/>";
}
Exemplo n.º 3
0
        $this->title = $title_in;
    }
    function getAuthor()
    {
        return $this->author;
    }
    function getTitle()
    {
        return $this->title;
    }
}
class BookAdapter
{
    private $book;
    function __construct(SimpleBook $book_in)
    {
        $this->book = $book_in;
    }
    function getAuthorAndTitle()
    {
        return $this->book->getTitle() . ' by ' . $this->book->getAuthor();
    }
}
define('BR', '<' . 'BR' . '>');
echo 'BEGIN TESTING ADAPTER PATTERN' . BR;
echo BR;
$book = new SimpleBook("Gamma, Helm, Johnson, and Vlissides", "Design Patterns");
$bookAdapter = new BookAdapter($book);
echo 'Author and Title: ' . $bookAdapter->getAuthorAndTitle();
echo BR . BR;
echo 'END TESTING ADAPTER PATTERN' . BR;