Skip to content

Commit

Permalink
Transformed initialization from to new TextSignedByAuthorFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
giorgiosironi committed Jan 25, 2012
1 parent 7241f6b commit cd5fa1e
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions ReplaceInheritanceWithDelegation.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@ public function testALinkShowsItsAuthor()
}
}

abstract class NewsFeedItem
class TextSignedByAuthorFormat
{
/**
* @var string references the author's Twitter username
*/
protected $author;

/**
* @return string an HTML printable version
*/
Expand All @@ -35,23 +30,19 @@ public function display($text, $author)
{
return "$text -- $author";
}

/**
* @return string
*/
protected abstract function displayedText();
}

class Post extends NewsFeedItem
class Post
{
private $text;
private $author;
private $format;

public function __construct($text, $author)
{
$this->text = $text;
$this->author = $author;
$this->format = $this;
$this->format = new TextSignedByAuthorFormat();
}

protected function displayedText()
Expand All @@ -65,16 +56,17 @@ public function __toString()
}
}

class Link extends NewsFeedItem
class Link
{
private $url;
private $author;
private $format;

public function __construct($url, $author)
{
$this->url = $url;
$this->author = $author;
$this->format = $this;
$this->format = new TextSignedByAuthorFormat();
}

protected function displayedText()
Expand Down

0 comments on commit cd5fa1e

Please sign in to comment.