A class should have only one reason to change.
(Robert C. Martin)
<?php
class Book {
function getTitle() {
return "A Great Book";
}
function getAuthor() {
return "John Doe";
}
function turnPage() {
// pointer to next page
}
function printCurrentPage() {
echo "current page content";
}
}
class Book
{
function getTitle()
{
return "A Great Book";
}
function getAuthor()
{
return "John Doe";
}
function turnPage()
{
// pointer to next page
}
function getCurrentPage()
{
return "current page content";
}
}
interface Printer
{
function printPage($page);
}
class PlainTextPrinter implements Printer
{
function printPage($page)
{
echo $page;
}
}
class HtmlPrinter implements Printer
{
function printPage($page)
{
echo '<div style="single-page">'
. $page
. '</div>';
}
}