ariestamirra

adapter

Aug 2nd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.96 KB | None | 0 0
  1. <?php
  2. class SimpleBook {
  3.     private $author;
  4.     private $title;
  5.     function __construct($author_in, $title_in) {
  6.         $this->author = $author_in;
  7.         $this->title  = $title_in;
  8.     }
  9.     function getAuthor() {
  10.         return $this->author;
  11.     }
  12.     function getTitle() {
  13.         return $this->title;
  14.     }
  15. }
  16. class BookAdapter {
  17.     private $book;
  18.     function __construct(SimpleBook $book_in) {
  19.         $this->book = $book_in;
  20.     }
  21.     function getAuthorAndTitle() {
  22.         return $this->book->getTitle().' by '.$this->book->getAuthor();
  23.     }
  24. }
  25.   // client
  26.   writeln('BEGIN TESTING ADAPTER PATTERN');
  27.   writeln('');
  28.   $book = new SimpleBook("Gamma, Helm, Johnson, and Vlissides", "Design Patterns");
  29.   $bookAdapter = new BookAdapter($book);
  30.   writeln('Author and Title: '.$bookAdapter->getAuthorAndTitle());
  31.   writeln('');
  32.   writeln('END TESTING ADAPTER PATTERN');
  33.   function writeln($line_in) {
  34.     echo $line_in."<br/>";
  35.   }
  36. ?>
Advertisement
Add Comment
Please, Sign In to add comment