Skip to content

Instantly share code, notes, and snippets.

@shaikhul
Created January 21, 2017 07:39
Show Gist options
  • Save shaikhul/2a72e9d5ae1632448b34142eaec11016 to your computer and use it in GitHub Desktop.
Save shaikhul/2a72e9d5ae1632448b34142eaec11016 to your computer and use it in GitHub Desktop.
<?php
/**
* Single Responsiblity Principle client code
*/
// create a book instance, book has no knowledge about rendering
$book = new Book();
$book->setTitle("Some Title");
$book->setAuthor("Some Author");
// now render it in plain text, specialized in Plain text only!
$plain_renderer = new PlainTextRenderer();
echo $plain_renderer->render($book->getCurrentPage());
// and now render in html, specialized in HTML only!
$html_renderer = new HTMLRenderer();
echo $html_renderer->render($book->getCurrentPage());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment