并發(fā)面向?qū)ο笾械睦^承反常現(xiàn)象
*
王生原 1+ ,? 楊良懷 2 ,? 袁崇義 3 ,? 楊 ? 萍 4
1 ( 清華大學 計算機科學與技術(shù)系 , 北京 ? 100084)
2 ( 新加坡國立大學 計算學院 計算機科學系 , 新加坡 )
3 ( 北京大學 計算機科學技術(shù)系 , 北京 ? 100871)
4 ( 蘭州大學 信息科學與工程學院 , 甘肅 蘭州 ? 730000)
Inheritance Anomaly in Concurrent Object Orientation *
WANG Sheng-Yuan1+,? YANG Liang-Huai2,? YUAN Chong-Yi3,? YANG Ping4
1 (Department of Computer Science and Technology, Tsinghua University, Beijing 100084, China)
2
(Department of Computer Science, School of Computing, National University of Singapore, Singapore)
3 (Department of Computer Science and Technology, Beijing University, Beijing 100871, China)
4
(School of Information Science and Technology, Lanzhou University, Lanzhou 730000, China)
+ Corresponding author: Phn: +86-10-62645407, Fax: +86-10-62645000, E-mail: wsy@163.net, http://www.tsinghua.edu.cn
Received
Abstract :?? The combination of concurrency and object orientation is definitely natural except for inheritance. One of the interferences between inheritance and concurrency is inheritance anomaly. Although having been researched extensively, inheritance anomalies are still only vaguely defined and often misunderstood, and no much formal work has been done. A new viewpoint is set forth for understanding inheritance anomalies, in which each subtyping relation has its specific incremental inheritance. Related concepts and definitions are formalized through the language of Category. Some issues are well adapted to distinguish and explain different standpoints about inheritance anomalies, and can serve as guidelines in the modeling of inheritance.
Key words :?????? concurrency; object orientation; inheritance anomaly; incremental inheritance; category theory
摘? 要
:????
如果不考慮繼承性
,
并發(fā)性與對象技術(shù)的結(jié)合是很自然的
.
繼承反常
(
又稱繼承異常
)
現(xiàn)象是繼承性和并發(fā)性不相容的主要原因之一
.
現(xiàn)階段人們對繼承反常現(xiàn)象的認識有許多模糊之處
,
出發(fā)點不盡相同
,
形式化的工作也很少
.
對不同的
subtyping
關(guān)系考慮其特有的漸增式繼承方法有利于把握繼承反常現(xiàn)象的實質(zhì)
,
也豐富了
“
在并發(fā)面向?qū)ο笳Z言中應(yīng)將
inheritance
層次和
subtyping
層次區(qū)別對待
”
這一認識的內(nèi)涵
.
在闡述基本觀點之后
,
采用范疇論的術(shù)語對相關(guān)的概念和定義做了形式化工作
.
一些觀點和結(jié)論適用于區(qū)分和解釋相關(guān)工作的出發(fā)點和貢獻
,
并對并發(fā)面向?qū)ο蠹夹g(shù)中繼承性的建模問題有所啟示
.
關(guān)鍵詞 :???? 并發(fā)性 ; 面向?qū)ο?/span> ; 繼承反常 ; 漸增式繼承 ; 范疇論
中圖法分類號 :? TP301 文獻標識碼 : A
Inheritance( 繼承 ) 是類 (class) 之間的一種層次關(guān)系 . 在一般的面向?qū)ο笳Z言中 , 類層次自動對應(yīng)了一種類型 (type) 層次 [1] , 這樣 ,superclass 和 subclass 之間的關(guān)系自然是一種 supertype 和 subtype 之間的關(guān)系 .
1? ?? 認識繼承反常現(xiàn)象
如圖 1 所示 , 類 Buffer 實現(xiàn)了一個有界緩沖區(qū)類型 , 可以并發(fā)地接受消息 put 和 get . 同步機制采用了 “method guards” 方式 , 即為每一個 method 附加一個 guard 謂詞 [2] . 構(gòu)造 Buffer 的另一個子類 LockableBuffer 也會引發(fā)同樣的問題 . 這種 “ 為獲得有效繼承而必須對父類代碼進行實質(zhì)性修改的現(xiàn)象 ” 就是所謂的繼承反常 (inheritance anomaly)[3~5].
2?
??
Interest patterns
Vector
clustering
Pattern
derivation
Feature
extraction
Document
database
Vector
database
Document
clusters
Interest
topics
Fig.1 ?Mining interest patterns
圖
1
?
興趣模式的挖掘過程
理解繼承反常現(xiàn)象
Interest patterns |
Vector clustering |
Pattern
derivation |
Feature extraction |
Document
database |
Vector
database |
Document
clusters |
Interest
topics |
Fig.1 ?Mining interest patterns 圖 1 ? 興趣模式的挖掘過程 |
2.1? ? 區(qū)別Inheritance 和Subtyping
綜合各種觀點 , 要理解和解釋繼承反常現(xiàn)象 , 首先必須正確區(qū)別 inheritance 層次和 subtyping 層次 , 并深刻領(lǐng)會二者的聯(lián)系 [6,7] . 對于這個問題 , 文獻 [1,8] 的觀點是比較權(quán)威的 . 在此基礎(chǔ)上 , 我們的理解是 :Inheritance 是在代碼層次上作修改 , 而 subtyping 是在語義層次上作修改 . 前者是代碼共享的一種重要途徑 , 但不能保證 subclass 能夠繼承 superclass 的行為 ; 后者要求 subtype 保持 supertype 的某種外部可觀察行為 ( 或語義行為 ), 在規(guī)范一級共享 , 同代碼沒有關(guān)系 .Inheritance 層次關(guān)系可以理解為 “is_similar_to”( 或 “l(fā)ike”) 的關(guān)系 , 而將 “is_a” 關(guān)系更適合用在理解 subtyping 層次關(guān)系上 , 見表 1[9].
Table 1 ?Latency of macro-instructions
表 1 ? 宏指令的時延
Acronym |
Macro-Instructions |
Latency (ns) |
Event symbol |
||
Value |
Symbol |
||||
NSI |
NET_SLICE_INIT() |
87 |
t
a
|
n
(
a
,e) |
? |
NST |
NET_SLICE_STOP() |
154 |
-
|
-
|
? |
NSE |
NET_SLICE_EXIT() |
904 (1.4%) |
t
g
|
n
(
g
,e) |
? |
NSO |
Inter-Overhead between NET_SLICE_START() and NET_SLICE_STOP() |
150 |
t
o
|
n
(o,e) |
? |
NSA |
Overhead of NET_SLICE_START() |
303 |
t
b
|
n
(
b
,e) |
? |
命題 1 . 設(shè) R í R L ,R ¢ í R ,R 定義的 Class 范疇為 C R ,R ¢ 定義的 Class 范疇為 C R ¢ , 則 C R ¢ 是 C R 的子范疇 , 并稱之為 C R 的子 Class 范疇 .
證明 : 對任何 A ,B ? ob C R =obCR ¢ ,homCR ¢ (A,B) í homCR (A,B).??????????????????????????????????????????????????????????????????????????????????? □
推論 1 . 任何 R í R L 定義的 Class 范疇 C R 都是 C L 的子 Class 范疇 .
2.2?
?
漸增式繼承
Subtyping 要求 subtype 保持 supertype 的某種行為 ( 可看作是一種不變量 , 比如同步約束 )[10].Subclass 在增加新的屬性或方法時 , 為了避免破壞這種不變量 , 難免要對繼承的代碼進行擴展或修改 . 這種擴 展或修改很可能是重大的或?qū)嵸|(zhì)性的 , 結(jié)果使得代碼共享失去意義 . 這便是繼承反常的直觀含義 .
假定非線性優(yōu)化問題 :
?????????????????????????????????????????????????????????????????????????????
的近似解為
步長
Internet
Response
Request
Browser
Front_end server
Back_end server
Back_end server
Back_end server
.
.
.
Fig.2? The framework of the TB-CCRD based DWSS
圖
2?
基于標記的緩存協(xié)作
DWSS
系統(tǒng)框架
2.2.1? ??? 定義繼承反常現(xiàn)象
本節(jié)是對上述觀點的形式化描述 , 可與第 2.2 節(jié)對照閱讀 . 范疇論的觀點層次較高 , 易于抽象出問題的本質(zhì) .
與程序 P 在 F 下運行等價的錯誤影響程序 PF 有
2.2.2?
???
(2)
InitPF
=
InitP
,
VarPF
=
VarF
,
UnitPF
=
e
[
A
1
?
F
;
A
2
?
F
;…;
An
?
F
]
,
WherePF
=
WhereP
ù
FaultAssumptionF
.
解釋繼承反常現(xiàn)象
(2) |
InitPF
=
InitP
,
VarPF
=
VarF
,
UnitPF
=
e
[
A
WherePF = WhereP ù FaultAssumptionF . |
例 1: 在談到順序面向?qū)ο笳Z言時 , 一般不涉及繼承反常現(xiàn)象 . 這是因為 , 這類語言 L 都默認一個特殊的 subtyping 關(guān) 系 p ( 由 R L 定義的完整 inheritance 層 次關(guān)系被默認為相應(yīng)于 p 的漸增式繼承關(guān)系 ), 它對應(yīng)的 Type 范疇記為 T L , 滿足 :CL 實現(xiàn) T L , 實現(xiàn)函子為 F : " A (A ? ob C L ? F A = type (A)).L 無 p - 繼承反常 . 因為順序面向?qū)ο笳Z言不提供定義 subtyping 關(guān)系的機制 , 所以這種默認的 subtyping 關(guān)系是語言中惟一的 subtyping 關(guān)系 , 這些語言 L 無繼承反常 .
3?
??
結(jié)束語
本文形式地給出了 “ 繼承反常現(xiàn)象 ” 的一種一般性定義 . 定義對每一種 Subtyping 關(guān)系都有其相對應(yīng)的 “ 漸增式繼承 ” , 使其更具有普適性 . 文中 “ 漸增式繼承 ” 是一個相對的概念 , 這有助于對人們 “ 使繼承反常現(xiàn)象得到緩解 ” 的努力得以分類和評價 .
致謝
?
在此
,
我們向?qū)Ρ疚牡墓ぷ鹘o予支持和建議的同行
,
尤其是北京大學計算機科學技術(shù)系
References
:
? [1]? ?? Clifton C, Leavens GT, Chambers C, Millstein T. MultiJava: modular open classes and symmetric multiple dispatch for Java. ACM SIGPLAN Notices, 2000,35(10):130-145.
? [2]? ?? Wegner P, Zdonik SB. Inheritance as an incremental modification mechanism or what like is and isn’t like. In: Gjessing S, Nygaard K, eds. Proc. of the ECOOP’88. LNCS 322, Heidelberg: Springer-Verlag, 1988. 55-77.
? [3]? ?? Waxman BM. Routing of multipoint connections. IEEE Journal on Selected Areas in Communications, 1988,6(9):1617-1622.
? [4]? ?? Yonezawa A. ABCL: An Object-Oriented Concurrent System. Cambridge: MIT Press, 1990.
? [5]? ?? Matsuoka S, Yonezawa A. Analysis of inheritance anomaly in object-oriented concurrent programming languages. In: Agha G, Wegner P, Yonezawa A, eds. Research Directions in Concurrent Object-Oriented Programming. Cambridge: MIT Press, 1993. 107-150.
? [6]? ?? Hemige V. Object-Oriented design of the groupware layer for the ecosystem information system [MS. Thesis]. University of Montana, 1995.
? [7]? ?? Rose A, Perez M, Clements P. Modechart toolset user’s guide. Technical Report, NML/MRL/5540-94-7427, Austin: University of Texas at Austin, 1994.
? [8]? ?? Keene SE. A Programmer’s Guide to Object-Oriented Programming in Common LISP. Boston: Addison-Wesley Longman Publishing Co., Inc., 1988.
? [9]? ?? Guo L, Tang ZS. Specification and verification of the triple-modular redundancy fault-tolerant system. Journal of Software, 2003,14(1):28~35 (in Chinese with English abstract). http://www.jos.org.cn/1000-9825/14/28.htm
[10]? ?? Schutze, H. Dimensions of meaning. In: Whitelock P, ed. Proc. of the Supercomputing’92. Los Alamitos, 1992. 787~796. ftp://parcftp.parc.xerox.com/pub/qca/papers/
[11]? ?? Wang XW. Research on quality-of-service management and group communication mechanisms in distributed multimedia systems [Ph.D. Thesis]. Shenyang: Northeastern University, 1998 (in Chinese with English abstract).
附中文參考文獻 :
? [9]??? 郭亮 , 唐稚松 . 三機冗余容錯系統(tǒng)的描述和驗證 . 軟件學報 ,2003,14(1):28-35. http://www.jos.org.cn/1000-9825/14/28.htm
[11]??? 王興偉 . 分布式多媒體系統(tǒng)服務(wù)質(zhì)量管理與組通信機制的研究 [ 博士學位論文 ]. 沈陽 : 東北大學 ,1998.
*
????
Supported by the National Natural Science Foundation of China under Grant No.60373000 (
國家自然科學基金
); the National High-Tech Research and Development Plan of China under Grant Nos.863-
作者簡介 : 王生原 (1964 - ), 男 , 山西應(yīng)縣人 , 博士 , 副教授 , 主要研究領(lǐng)域為分布對象計算 ,Petri 網(wǎng)應(yīng)用 , 嵌入式軟件環(huán)境 ; 楊良懷 (1967 - ), 男 , 博士 , 講師 , 主要研究領(lǐng)域為數(shù)據(jù)庫系統(tǒng)實現(xiàn)技術(shù) , 數(shù)據(jù)倉庫 , 半結(jié)構(gòu)化數(shù)據(jù) ,Web 數(shù)據(jù)集成 , 數(shù)據(jù)挖掘 ; 袁崇義 (1941 - ), 男 , 教授 , 博士生導師 , 主要研究領(lǐng)域為并行計算 ,Petri 網(wǎng)理論及應(yīng)用 ; 楊萍 ( 1964 - ), 女 , 副教授 , 主要研究領(lǐng)域為人工智能 .
凡是有該標志的文章,都是該blog博主Caoer(草兒)原創(chuàng),凡是索引、收藏
、轉(zhuǎn)載請注明來處和原文作者。非常感謝。