大家都遇到过类似问题吗?
刚用PHP的类不久,对此深有感触!
不知道大家遇到这种问题时都是怎么解决的!希望大家顶上去,别让这贴子早早沉了!
刚用PHP的类不久,对此深有感触!
不知道大家遇到这种问题时都是怎么解决的!希望大家顶上去,别让这贴子早早沉了!
解决方案 »
- Windows Vista上怎样安装linux
- 小弟求教:什么是封装,怎么写
- 网站成功改版,散分!来顶的都有分O(∩_∩)O~
- 大家来看看这个效果,你们见过没,有没有拿过来就可以用的?
- 求正则表达式
- 关于mysql数值型数据定义问题。最后的40份,全给拉。
- 有个问题,为什么我在iis中,配置了php,php文件可以正常运行
- 请问怎么让浏览器不读cache我的浏览器每回都要手动刷新,累啊
- 谁有session 写的购物篮程序,给我一份吧。我送100分!
- 关于PHP一点疑惑
- php不用apache服务器,在iis下如何运行和设置?
- 晕,放在数据库区居然没人能答上来的问题:取列的字段名称:一个有100个字段的数据表,想把字段不为空的取出来,SQL语句怎么写?
PHP5已经有接口的概念了。这时候可以采用接口来解决,再接口中声明该方法,然后再二个类中分别实现该接口,虽然名称相同,但具体功能代码可能会有些差别。类的划分一般以完成某一类功能为主,最大程度的降低类之间的耦合度。
因为刚刚接触类不久,以前都是有阿头帮我规划好的.
现在要自己划分类,还真的比较困难,头都大了. keaizhong(可爱钟) ( )
zhiin(稚鹰来CSDN交朋友)
xuzuning(唠叨)
ice_berg16(寻梦的稻草人)
mikespook(懒猫开始新生活)这么多位大哥,能给小弟一个划分类的方法吗?[稍微指点一下也行]谢谢大家了.
|
CXMLHandler(DeleteNode, AddNode, EditNode, ReadNode)
|
CSOAPParser, CXMLConfig, CXMLSQL, ... (各种XML应用)继承是OO的三个特征之一(封装,继承,多态)
{
public $thisMonthCount;
public $lastMonthCount;
public $thisDayCount;
public $lastDayCount;
public $totalCount;
public $beginDate;
public $totalDayCount; public $avgCount; public $mysqli; function __construct()
{
$this->mysqli = $GLOBALS['mysqli'];
} /**
* Function: 分别创建记数器所需的两个表(count, online). 如果已存在则先删除再创建
*/
private function createTable()
{
$this->mysqli->query("drop table if exists `count`");
$query = "CREATE TABLE `count` (
`id` tinyint(4) NOT NULL default '1',
`this_month` int(6) NOT NULL default '0',
`last_month` varchar(6) NOT NULL default '0',
`this_day` varchar(5) NOT NULL default '0',
`last_day` varchar(5) NOT NULL default '0',
`total` int(11) NOT NULL default '0',
`begin_date` date NOT NULL,
`count_date` date NOT NULL,
PRIMARY KEY (`id`)
)";
$this->mysqli->query($query); $this->mysqli->query("drop table if exists `online`");
$query = "CREATE TABLE `online` (
`id` int(11) NOT NULL auto_increment,
`ip` varchar(16) NOT NULL,
`time` datetime default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `ip` (`ip`)
)";
$this->mysqli->query($query);
} /**
* Function: 初始化记数器, 包括count与online两张表的重新创建
*/
function reset()
{
$this->createTable();
$this->mysqli->query("insert into `count` (`id`, `this_month`, `last_month`, `this_day`, `last_day`, `total`, `begin_date`, `count_date`)
values ('1', 0, 0, 0, 0, 0, now(), now())");
} /**
* Function: 记数器无条件记数
*/
private function increment()
{
$result = $this->mysqli->query("select day(`count_date`) as `day`, month(`count_date`) as `month` from `count`");
$row = $result->fetch_assoc();
$monthOfCountDate = $row['month'];
$dayOfCountDate = $row['day']; $monthOfDate = date("n");
$dayOfDate = date("j");
$monthOfLastDate = date("n", strtotime ("-1 month"));
$dayOfLastDate = date("j", strtotime ("-1 day"));
if($monthOfCountDate==$monthOfDate && $dayOfCountDate==$dayOfDate)
{
$this->mysqli->query("update `count` set `this_month` = `this_month` + 1, `this_day` = `this_day` + 1, `total` = `total` + 1");
}
elseif($monthOfCountDate==$monthOfDate && $dayOfCountDate!=$dayOfDate)
{
if($dayOfCountDate==$dayOfLastDate)
{
$this->mysqli->query("update `count` set `this_month` = `this_month` + 1, `last_day` = `this_day`, `this_day` = 1, `total` = `total` + 1, `count_date` = now()");
}
else
{
$this->mysqli->query("update `count` set `this_month` = `this_month` + 1, `last_day` = 0, `this_day` = 1, `total` = `total` + 1, `count_date` = now()");
}
}
elseif($monthOfCountDate!=$monthOfDate)
{
if($monthOfCountDate==$monthOfLastDate && $dayOfCountDate==$dayOfLastDate)
{
$this->mysqli->query("update `count` set `last_month` = `this_month`, `this_month` = 1, `last_day` = `this_day`, `this_day` = 1, `total` = `total` + 1, `count_date` = now()");
}
elseif($monthOfCountDate==$monthOfLastDate && $dayOfCountDate!=$dayOfLastDate)
{
$this->mysqli->query("update `count` set `last_month` = `this_month`, `this_month` = 1, `last_day` = 0, `this_day` = 1, `total` = `total` + 1, `count_date` = now()");
}
elseif($monthOfCountDate!=$monthOfLastDate)
{
$this->mysqli->query("update `count` set `last_month` = 0, `this_month` = 1, `last_day` = 0, `this_day` = 1, `total` = `total` + 1, `count_date` = now()");
}
}
} /**
* Function: 记录器有条件记数(不在线时才记数, 在线的仅更新活动时间)
*/
function count()
{
$online = new Online();
if($online->isOnline())
{
$online->updateOnlineTime();
}
else
{
$online->increment();
$this->increment();
}
} /**
* Function: 初始化记数器的每一个属性
*/
function init()
{
$result = $this->mysqli->query("select *, to_days(now())-to_days(`begin_date`)+1 as `totalDayCount` from `count`");
$row = $result->fetch_assoc(); $this->thisMonthCount = $row['this_month'];
$this->lastMonthCount = $row['last_month'];
$this->thisDayCount = $row['this_day'];
$this->lastDayCount = $row['last_day'];
$this->totalCount = $row['total'];
$this->countDate = $row['count_date'];
$this->beginDate = $row['begin_date'];
$this->totalDayCount = $row['totalDayCount'];
$this->avgCount = round($this->totalCount/$this->totalDayCount);
} /**
* Function: 以HTML方式显示记数器各属性
*/
function printHtml()
{
$this->init(); $online = new Online(); echo "<ul class=\"counter\">
<li>本站总访问: {$this->totalCount}人</li>
<li>今日访问量: {$this->thisDayCount}人</li>
<li>昨日访问量: {$this->lastDayCount}人</li>
<li>本月访问量: {$this->thisMonthCount}人</li>
<li>上月访问量: {$this->lastMonthCount}人</li>
<li>本站已运行: {$this->totalDayCount}天</li>
<li>平均访问量: {$this->avgCount}人</li>
<li>当前有 {$online->getOnlineCount()} 人在线</li>
</ul>";
}
}?>
{
public $mysqli; function __construct()
{
$this->mysqli = $GLOBALS['mysqli'];
} /**
* Function: 更新online表(删除online里3分钟无动作的用户)
*/
private function updateOnline()
{
$this->mysqli->query("delete from `online` where unix_timestamp(now()) - unix_timestamp(`time`) > 3*60");
} /**
* Function: 先更新online表, 然后判断用户是否在线, 如在线返回true,不在线返回false
*/
function isOnline()
{
$this->updateOnline();
$ip = getip();
$result = $this->mysqli->query("select count(*) as `count` from `online` where `ip` = '$ip'");
$row = $result->fetch_assoc();
if($row['count']==1)
{
return true;
}
else
{
return false;
}
} /**
* Function: 先更新online表, 然后返回在线人数
*/
function getOnlineCount()
{
$this->updateOnline();
$result = $this->mysqli->query("select count(*) as `count` from `online`");
$row = $result->fetch_assoc();
return $row['count'];
} /**
* Function: 记录在线信息到online
*/
function increment()
{
$ip = getip();
$this->mysqli->query("insert into `online` (`id`, `ip`, `time`) value ('', '$ip', now())");
} /**
* Function: 更新在线IP的活动时间
*/
function updateOnlineTime()
{
$ip = getip();
$this->mysqli->query("update `online` set `time` = now() where `ip` = '$ip'");
}
}?>
<?
$counter = new Counter;
//$counter->reset(); 初始化
$counter->count();
$counter->printHtml();
?>其中的getip()函数为:function getip()
{
return !empty($_SERVER['HTTP_CLIENT_IP']) ? $_SERVER['HTTP_CLIENT_IP'] : (!empty($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']);
}
也就是说有特性的东西部要不要和共性的东西放一块,把那些特性的东西和共性的东西混在一块最终将严重影响共性。怎么样用一个构架把许多有共性的问题粘合在一起来应付特性我觉得比较有意义。
也就是高内聚低耦合。但是要做到挺困难的,经验和技巧一个都不能少。
SOAP,CONFIG这些不因该继承XML类
而因该聚合一个XML处理对象
因为这些类没有使用xml类的方法
登录,
修改资料,
应聘职位,
查看应聘历史,
保存搜索条件功能,用户类
职位类
登陆类
应聘关系类
似乎还会有
企业类
招聘广告类
等等
这些都是model部分
可以找OO分析设计的书,UML的书看