PHP之装饰器模式
来源:互联网 发布:java将链接生成二维码 编辑:程序博客网 时间:2024/04/27 18:53
<?php
abstract class AbstractRating {
protected $decoratable;
public function __construct( $decoratable ) {
$this -> decoratable = $decoratable;
}
abstract public function getRating();
}
class PoorRating extends AbstractRating {
protected $rating = 1;
public function __construct($decoratable) {
parent::__construct( $decoratable );
}
public function getRating() {
return $this -> decoratable -> getRating() + $this -> rating;
}
}
class AverageRating extends AbstractRating {
protected $rating = 2;
public function __construct( $decoratable ) {
parent::__construct( $decoratable );
}
public function getRating() {
return $this -> decoratable -> getRating() + $this -> rating;
}
}
class GoodRating extends AbstractRating {
protected $rating = 3;
public function __construct( $decoratable ) {
parent::__construct( $decoratable );
}
public function getRating() {
return $this -> decoratable -> getRating() + $this -> rating;
}
}
class Ratings {
private $rating = 3;
public function __construct() { }
public function getRating() {
return $this -> rating; // typeof integer
}
}
$rating = new GoodRating( new AverageRating( new Ratings ) ); // we are decorating the Ratings object
echo($rating -> getRating());
?>
abstract class AbstractRating {
protected $decoratable;
public function __construct( $decoratable ) {
$this -> decoratable = $decoratable;
}
abstract public function getRating();
}
class PoorRating extends AbstractRating {
protected $rating = 1;
public function __construct($decoratable) {
parent::__construct( $decoratable );
}
public function getRating() {
return $this -> decoratable -> getRating() + $this -> rating;
}
}
class AverageRating extends AbstractRating {
protected $rating = 2;
public function __construct( $decoratable ) {
parent::__construct( $decoratable );
}
public function getRating() {
return $this -> decoratable -> getRating() + $this -> rating;
}
}
class GoodRating extends AbstractRating {
protected $rating = 3;
public function __construct( $decoratable ) {
parent::__construct( $decoratable );
}
public function getRating() {
return $this -> decoratable -> getRating() + $this -> rating;
}
}
class Ratings {
private $rating = 3;
public function __construct() { }
public function getRating() {
return $this -> rating; // typeof integer
}
}
$rating = new GoodRating( new AverageRating( new Ratings ) ); // we are decorating the Ratings object
echo($rating -> getRating());
?>
- PHP之装饰器模式
- php设计模式之装饰器模式
- 【设计模式】之装饰器模式-PHP
- PHP设计模式之装饰器模式
- PHP设计模式之装饰器模式
- PHP 设计模式之装饰器模式
- php设计模式之装饰器
- php-装饰器模式
- PHP 装饰器模式
- php之大话装饰模式
- php设计模式之———装饰器模式
- 【设计模式】之装饰器模式(二)-PHP
- php八大设计模式之装饰器模式
- PHP设计模式中之装饰模式
- PHP设计模式之装饰模式
- Php设计模式之装饰者模式
- PHP设计模式之装饰者模式
- php 设计模式 之 装饰模式
- 从MDF文件恢复Sql Server2000数据库
- Excel与OWC做报表总结(转载)
- 登陆后自动注销的解决办法
- 交房注意事项 买房一辈子的家
- 测试驱动实践
- PHP之装饰器模式
- spring中文文档(地址)
- 如何在asp.net中调用存储过程?
- 类型转换
- 介绍一种巧妙的删除程序自己的方法
- 中国人不可不知道的知识(转)
- Ext2.0版的布局类(与1.0的区别)
- 使用 Reporting Services 中的窗体身份验证
- JAVA学习的一些重点