Let us see how we can use that:
$post = new Post();//set the properties of the post object
$comment = new Comment();//set the properties of the comment object
$post->filter();
$comment->filter();
if ($BBCodeEnabled==false && $EmoticonEnabled==false)
{
$PostContent = $post->getContent();
$CommentContent = $comment->getContent();
}
elseif ($BBCodeEnabled==true && $EmoticonEnabled==false)
{
$bb = new BBCodeParser($post);//passing a post object to
//BBCodeParser
$PostContent = $bb->getContent();
$bb = new BBCodeParser($comment);//passing a comment object to
//BBCodeParser
$CommentContent = $bb->getContent();
}
elseif ($BBCodeEnabled==true && $EmoticonEnabled==false)
{
$em = new EmoticonParser($post);
$PostContent = $bb->getContent();
$em = new EmoticonParser($comment);
$CommentContent = $bb->getContent();
}
?>
This is how you can add additional functionalities to existing objects without even
touching them. However, you saw that BBCodeParser and EmoticonParser accept
any object, which means that if you supply an object, which doesn't have any
method named getContent(), the code will crash. So you can implement a common
interface in those objects, which you might want to decorate.
Pages:
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110