Copy CodeThe code is as follows:
<?php
/**
* Decoration mode
*
* Dynamically adding some additional responsibilities to an object, which is more flexible than generating subclasses in terms of extended functionality
*/
Header ("Content-type:text/html;charset=utf-8");
Abstract class Messageboardhandler
{
Public Function __construct () {}
Abstract Public Function filter ($MSG);
}
Class Messageboard extends Messageboardhandler
{
Public Function filter ($MSG)
{
Return "process the content on the message board". $msg;
}
}
$obj = new Messageboard ();
echo $obj->filter ("Be sure to learn the decoration mode <br/>");
---The following is the use of decorative mode----
Class Messageboarddecorator extends Messageboardhandler
{
Private $_handler = null;
Public function __construct ($handler)
{
Parent::__construct ();
$this->_handler = $handler;
}
Public Function filter ($MSG)
{
return $this->_handler->filter ($msg);
}
}
Filtering HTML
Class Htmlfilter extends Messageboarddecorator
{
Public function __construct ($handler)
{
Parent::__construct ($handler);
}
Public Function filter ($MSG)
{
Return "filter out HTML tags". parent::filter ($MSG); Filtering out the processing of HTML tags just add text without processing
}
}
Filter sensitive words
Class Sensitivefilter extends Messageboarddecorator
{
Public function __construct ($handler)
{
Parent::__construct ($handler);
}
Public Function filter ($MSG)
{
Return "filter out sensitive words". Parent::filter ($MSG); Filter out the processing of sensitive words just add text without processing
}
}
$obj = new Htmlfilter (new Sensitivefilter messageboard ());
echo $obj->filter ("must learn to decorate the pattern!<br/>");
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service