Copy CodeThe code is as follows:
/**
* Decoration mode
*
* Dynamically add some additional responsibilities to an object, which is more flexible than generating subclasses in terms of extension 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 "processing the content on the message board |". $msg;
}
}
$obj = new Messageboard ();
echo $obj->filter ("Be sure to learn the decorative pattern
");
---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);; Filter out HTML tag processing This is just a text that is not processed.
}
}
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 sensitive word processing this is just a text that's not processed.
}
}
$obj = new Htmlfilter (new Sensitivefilter (New Messageboard ()));
echo $obj->filter ("Be sure to learn the decorative pattern!"
");
The above describes the dvd.taiwan-sex.com PHP design mode decorator decorative mode, including the dvd.taiwan-sex.com aspects of the content, I hope that the PHP tutorial interested in a friend helpful.