Posted on 2011/10/26, 2:05 pm, by zhangv, under
技术(Tech).
面向对象和是否使用充血模型,是两个概念,不存在冲突。
如果使用充血模型,你的代码读起来就好像:今天他来了,然后他死了。 – he.goto(Place,TrafficTool); he.died(DeadReason);
而贫血模型的话,读起来就像是:一辆大巴载着他来了,然后死神带走了他。 – bus.taketo(He,Place); death.takeaway(He);
“他”就是模型,在整个编程模型中怎么理解他至关重要,否则在开发团队里就存在混用的情况。用哪种模型完全取决于个人喜好。
一般充血模型比较适合逻辑不是很复杂,比如大多数都是单表,不存在复杂的关联的情况。贫血模型的使用范围比较广,用着也简单,但代码看起来多,而且读起来吞吞吐吐。毕竟充血模型需要在扩展时非常清楚合理地把行为定义到正确的模型上。
Posted on 2009/06/24, 10:26 am, by zhangv, under
技术(Tech).
Discuz的代码还是比较容易看懂的。关键是要找到需要改的地方。第1步:forumdisplay.php,用来准备要显示的帖子列表,然后用forumdisplay.htm作为显示模板。找到forumdisplay.php中的:$query = $sdb->query(”SELECT t.* FROM {$tablepre}threads t WHERE t.fid=’$fid’ $filteradd AND $displayorderadd ORDER BY t.displayorder DESC, t.$orderby $ascdesc LIMIT “.($filterbool ? $start_limit : $start_limit – $stickycount).”, $tpp”);
替换为:$query = $sdb->query(”SELECT t.*,min(att.attachment) as attm FROM {$tablepre}threads t LEFT JOIN {$tablepre}posts p ON p.tid=t.tid LEFT JOIN {$tablepre}attachments att ON att.tid=t.tid WHERE t.fid=’$fid’ [...]
Posted on 2009/03/18, 10:28 pm, by zhangv, under
技术(Tech).
下面这段vbs代码会将当前的目录加入到路径,同时添加一个新的环境变量,值为当前路径
Set WshShell = WScript.CreateObject(”WScript.Shell”) Set Env = WshShell.Environment(”SYSTEM”) WScript.Echo Env(”Path”) currentDirectory = left(WScript.ScriptFullName,(Len(WScript.ScriptFullName))-(len(WScript.ScriptName))) Env(”TODOR_BASE”) = currentDirectory
currentPath = Env(”Path”)pos = InStr(currentPath,currentDirectory)if pos=0 then Env(”Path”) = currentPath & “;” & currentDirectoryend if
WScript.Echo “Setup successfully!”
Posted on 2008/07/05, 2:19 pm, by zhangv, under
技术(Tech).
很早前在学校时候写的一个生成目录文件列表的东西,因为那时候自己开了一个ftp服务器。
import java.util.Date;
import java.util.Arrays;
import java.io.*;
/**
* Time: 2003-12-23 20:46:42
*/
public class FileManager {
private String ListFilename = "@list.txt";
private String root;
private String updatetime;
public FileManager(String root) {
this.root = root;
updatetime=new Date().toString();
}
private void getList(String dir) {
File tmp = new File(dir);
File[] files = tmp.listFiles(new ffilter());
File[] dirs = tmp.listFiles(new dfilter());
if (files.length != 0) {
writeListFile(files);
}
if (dirs.length != 0) {
for (int i = 0; i < dirs.length; [...]
Posted on 2008/06/11, 10:12 am, by zhangv, under
技术(Tech).
Posted on 2007/12/14, 4:39 pm, by zhangv, under
技术(Tech).
<script type=”text/javascript” language=”JavaScript”><!–
function HideContent(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = “none”;
}
function ShowContent(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = “block”;
}
function ReverseContentDisplay0(d) {
if(d.length < 1) { return; }
if(document.getElementById(d).style.display == “none”) { document.getElementById(d).style.display = “block”; }
else { document.getElementById(d).style.display = “none”; }
}
function ReverseContentDisplay(d) {
if(d.length < 1) { return; }
for(i=1;i<=3;i++){
var tmp = ‘block’+i;
if(d==tmp){
if(document.getElementById(d).style.display == “none”) { document.getElementById(d).style.display = [...]