国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

策略模式

2019-11-08 02:01:58
字體:
供稿:網(wǎng)友
<?php// 策略模式interface Calculator{	public function calc($a, $b);}/** * add strategy */class AddCalculator implements Calculator{	public function calc($a, $b)	{		return intval($a) + intval($b);	}}/** * multiply stategy */class MultiplyCalculator implements Calculator{	public function calc($a, $b)	{		return intval($a) * intval($b);	}}// -------------------------------------------------------/** * sample code */class StrategySample{	PRivate $calc;	public function __construct(Calculator $c = NULL)	{		if(!is_null($c))			$this->calc = $c;	}	/**	 * set calculator	 */	public function setCalculator(Calculator $c)	{		$this->calc = $c;	}	/**	 * get calculator	 */	public function getCalculator()	{		return $this->calc;	}	public function doCalc($a, $b)	{		return $this->calc->calc($a, $b);	}}// test code$add = new AddCalculator();$strategy = new StrategySample($add);echo $strategy->doCalc(2, 3);echo '<br>';$strategy->setCalculator(new MultiplyCalculator());echo $strategy->doCalc(2, 3);
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 喀什市| 淮阳县| 安多县| 怀远县| 南皮县| 蒲江县| 屯留县| 涞水县| 库车县| 陆川县| 夏邑县| 老河口市| 茶陵县| 资溪县| 北京市| 边坝县| 鄂托克旗| 图片| 从江县| 任丘市| 淮滨县| 广元市| 读书| 英吉沙县| 怀仁县| 千阳县| 东城区| 洛扎县| 德庆县| 灌云县| 公主岭市| 沛县| 怀仁县| 云安县| 南召县| 鄂州市| 西平县| 柘荣县| 淮南市| 宜兴市| 霸州市|