} } //过滤html class HtmlFilter extends MessageBoardDecorator { public function __construct($handler) { parent::__construct($handler); } public function filter($msg) { return "过滤掉HTML标签|" . parent::filter($msg); //过滤掉html标签的处理 } } //过滤敏感词 class SensitiveFilter extends MessageBoardDecorator { public function __construct($handler) { parent::__construct($handler); } public function filter($msg) { return "过滤掉敏感词|" . parent::filter($msg); //过滤掉敏感词的处理 } } $obj = new HtmlFilter(new SensitiveFilter(new MessageBoard())); echo $obj->filter("must learn decorator pattern well.\n");
class HtmlFilter extends MessageBoardDecorator { public function __construct($handler) { parent::__construct($handler); } public function filter($msg) { return "过滤掉HTML标签|" . parent::filter($msg); // 过滤掉HTML标签的处理 这时只是加个文字 没有进行处理 } } // 过滤敏感词 class SensitiveFilter extends MessageBoardDecorator { public function __construct($handler) { parent::__construct($handler); } public function filter($msg) { return "过滤掉敏感词|" . parent::filter($msg); // 过滤掉敏感词的处理 这时只是加个文字 没有进行处理 } } $obj = new HtmlFilter(new SensitiveFilter(new MessageBoard())); echo $obj->filter("一定要学好装饰模式!<br/>"); /** * 常用到的地方: * Java IO */