dvd.taiwan-sex.com PHP design mode decorator Decorative mode

Source: Internet
Author: User
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.

  • Contact Us

    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

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.