策略模式
来源:互联网 发布:sql server 官网 编辑:程序博客网 时间:2024/06/05 11:26
<?php
interface Strategy
{
public function showAd();
public function showGt();
}
require_once "Strategy.php";
class MaleGrategy implements Strategy
{
public function showAd()
{
echo "Male Ad<br/>";
}
public function showGt()
{
echo "Male Gt<br/>";
}
}
require_once "Strategy.php";
class FemaleGrategy implements Strategy
{
public function showAd()
{
echo "Female Ad<br/>";
}
public function showGt()
{
echo "Female Gt<br/>";
}
}
require_once "MaleGrategy.php";
require_once "FemaleGrategy.php";
class Index
{
public $object;
public function setStrategy($object)
{
$this->object = $object;
}
public function showAd()
{
$this->object->showAd();
}
public function showGt()
{
$this->object->showGt();
}
}
if(isset($_GET['type']) && $_GET['type'] == "male")
{
$object = new MaleGrategy();
} else {
$object = new FemaleGrategy();
}
$index = new Index();
$index->setStrategy($object);
$index->showAd();
$index->showGt();
?>
interface Strategy
{
public function showAd();
public function showGt();
}
require_once "Strategy.php";
class MaleGrategy implements Strategy
{
public function showAd()
{
echo "Male Ad<br/>";
}
public function showGt()
{
echo "Male Gt<br/>";
}
}
require_once "Strategy.php";
class FemaleGrategy implements Strategy
{
public function showAd()
{
echo "Female Ad<br/>";
}
public function showGt()
{
echo "Female Gt<br/>";
}
}
require_once "MaleGrategy.php";
require_once "FemaleGrategy.php";
class Index
{
public $object;
public function setStrategy($object)
{
$this->object = $object;
}
public function showAd()
{
$this->object->showAd();
}
public function showGt()
{
$this->object->showGt();
}
}
if(isset($_GET['type']) && $_GET['type'] == "male")
{
$object = new MaleGrategy();
} else {
$object = new FemaleGrategy();
}
$index = new Index();
$index->setStrategy($object);
$index->showAd();
$index->showGt();
?>
阅读全文
0 0
- 策略模式
- 策略模式
- 策略模式
- 策略模式
- 策略模式
- 策略模式
- 策略模式
- 策略模式
- 策略模式
- 策略模式
- 策略模式
- 策略模式
- 策略模式
- 策略模式
- 策略模式
- 策略模式
- 策略模式
- 策略模式
- idea mybatis maven generate命令
- Java_基础—图片加密
- Android 自动获取输入短信验证码库AutoVerifyCode
- java高并发解决方案
- 莫队算法总结
- 策略模式
- 前端跨域请求原理及实践
- hdu 5246 超级赛亚ACMer【二分or模拟】
- iOS ijkplayer视频直播框架
- mysql生成日历脚本(年|年月 格式)
- Android零基础入门第13节:Android Studio配置优化,打造开发利器
- Java 5
- Android 6.0 变更
- 在modal中调用codemirror