<?php
abstract class baseAgent{
abstract function PrintPage();
}
class ieAgent extends baseAgent{
function PrintPage(){
return "当前浏览器是IE!";
}
}
class otherAgent extends baseAgent{
function PrintPage(){
return "当前浏览器不是IE!";
}
}
if(strstr($_SERVER["HTTP_USER_AGENT"],"IEAGENT"))
{
$currPage=new ieAgent();
}
else{
$currPage=new otherAgent();
}
echo $currPage->PrintPage();
?>
转载于:https://www.cnblogs.com/chenyuanfeng/archive/2011/05/10/2041786.html
本文通过一个简单的PHP示例介绍了如何使用抽象类定义通用的行为,并根据不同的条件实例化具体的子类。此方法用于根据不同浏览器类型返回定制化的消息。
579

被折叠的 条评论
为什么被折叠?



