現(xiàn)在我們已經(jīng)明白了TCL數(shù)據(jù)文件的常見方法(主動文件,英語言過程,選項(xiàng)/數(shù)值對),我們可以將其各自的優(yōu)點(diǎn)組合進(jìn)一個單獨(dú)的數(shù)據(jù)格式中去.對強(qiáng)制性選項(xiàng),我們使用固定位置參數(shù)時,多半與啞介詞相結(jié)合增強(qiáng)可讀性(見英語言過程).而所有的可隨意選擇的選項(xiàng),宜用選項(xiàng)/數(shù)值對機(jī)制來進(jìn)行處理,好讓用戶可以空著選項(xiàng)或在調(diào)用時改變其位置.最后,數(shù)據(jù)文件可能會是這樣的:
d_rect from 10 10 to 150 50 -thickness 2
d_rect from 7 7 to 153 53 -thickness 2
d_text at 60 30 "Simple Drawing Tool" -anchor c -color red假定所有項(xiàng)目的color屬性的默認(rèn)值都是"blue".
作為一個個人習(xí)慣,我通常會寫這樣的命令:
d_rect
from 10 10
to 150 50
-thickness 2
d_rect
from 7 7
to 153 53
-thickness 2
d_text
at 80 30 "Simple Drawing Tool"
-anchor c
-color redI find it slightly more readable, but that"s all a matter of personal taste (or in my case lack of taste :-).
我覺得可讀性要好一些,但這僅是一個個人偏好的問題.(or in my case lack of taste)(這句話是作者在調(diào)侃自己,但我不知如何把它譯出來,請哪位大俠幫忙指點(diǎn)一下,譯者注)
--------------------------------------------------------------------------------
▲更多復(fù)雜的數(shù)據(jù)
至今為止,我們已經(jīng)對一個非常簡單的包含矩形與文本的例子進(jìn)行了研究.這種數(shù)據(jù)格式用主動文件設(shè)計(jì)樣本非常容易讀取并加以分析.
現(xiàn)在我們來看一個更為復(fù)雜的數(shù)據(jù)格式,來解釋一下使用主動文件的更加"高級"的技巧.這將使你在使用TCL數(shù)據(jù)文件格式方面成為一個專家.
▲數(shù)據(jù)倉庫工具
我過去經(jīng)常收集設(shè)計(jì)樣本,組成了一個樣本庫,每個都有一個簡短的說明和一些屬性.我還把在其中找到樣本的書的名字,作者和ISBN號記下來,作為以后查找時的參考.為了記錄所有這些信息,我用TCL寫了一個數(shù)據(jù)倉庫工具.其主要功能是把樣本按照類別和級別進(jìn)行分類,指出全書中每一個樣本和講述它的頁碼.
此工具的輸入是與此相似的一個文件:#首先,我介紹一些你從中可以找到好的設(shè)計(jì)樣本的書和設(shè)計(jì)程序時的習(xí)慣寫法.每一本書,
#每一個網(wǎng)址,或是其他的樣本資源都用關(guān)鍵字"source"指定,后跟一個唯一的標(biāo)簽及其他附
#加信息Source GOF {
Design patterns
Elements of reusable object-oriented software
Gamm, Helm, Johnson, Vlissides
Addison-Wesley, 1995
0 201 63361 2
}Source SYST {
A system of patterns
Pattern-oriented software architecture
Buschmann, Meunier, Rohnert, Sommerlad, Stal
Wiley, 1996
0 471 95869 7
}
#下一步,我介紹一些類別,為了更容易找到樣本,我想把樣本進(jìn)行分組.每個類別都
#有一個名稱(如"存取控制")和一個簡短的說明.
Category "Access control" {
How to let one object control the access to one or more
other objects.
}Category "Distributed systems" {
Distributing computation over multiple processes, managing
communication between them.
}Category "Resource handling" {
Preventing memory leaks, managing resources.
}Category "Structural decomposition" {
To break monoliths down into indpendent components.
}#最后,我介紹了樣本本身,每一個都有一個名字,屬于一個或多個類別,出現(xiàn)在上述樣
#本資源列表的一處或多處.每個樣本都有級別,可能是"arch"(對于結(jié)構(gòu)型樣本),
#"design"代表較小規(guī)模的設(shè)計(jì)樣本,"idiom"代表語言指定型樣本.
Pattern "Broker" {
Categories {"Distributed systems"}
Level arch
Sources {SYST:99} ; # 這表示此樣本在標(biāo)記為"SYST"的書中
# 第99頁加以講述.
Info {
Remote service invocations.
}
}Pattern "Proxy" {
# This pattern fits in two categories:
Categories {"Access control" "Structural decomposition::object"}
Level design
# Both these books talk about the Proxy pattern:
推薦閱讀
- 我TCL6198
- 王者清理游戲數(shù)據(jù)后果
- 我的 TCL768 一周使用經(jīng)歷
- FreeBSD 數(shù)據(jù)遷移方法
- MIUI11怎么備份數(shù)據(jù)
- 內(nèi)交外換 明基P30數(shù)據(jù)交換能力初探
- 金融信用信息基礎(chǔ)數(shù)據(jù)庫是征信嗎
- 10 FreeBSD連載:系統(tǒng)啟動腳本
- 安裝鴻蒙系統(tǒng)數(shù)據(jù)會丟失嗎
- 關(guān)于W219的數(shù)據(jù)傳輸
