ѧ
JOURNAL OF SOFTWARE
2000Vol.11No.4P.481-487




Zͼ̳к
Ʒ塡š֣
ժҪCOOZ(complete object-oriented Z)еļ̳йϵ,̳зΪ̳кͻ̳,صͻ̳.һΪͻ̳,֤˸÷ĺ,ݴ˶COOZĹԼ̳мԼ̳е.۵ͻE.Cusack˵ķ,пɹ,ұLiskov˵ķи.
ؼʡʽ,,̳,,ʽԼ.
ͼšTP311
On Subtyping Inheritance and Inference Rules in Object-Oriented Z
WANG Yun-feng
tate Key Laboratory for Novel Software TechnologyNanjing UniversityNanjing210093
Meteorology CollegePLA University of TechnologyNanjing UniversityNanjing211101
LI Bi-xin
tate Key Laboratory for Novel Software TechnologyNanjing UniversityNanjing210093
ZHENG Guo-liang
tate Key Laboratory for Novel Software TechnologyNanjing UniversityNanjing210093
Abstract The inheritance relation of COOZ is discussed. It is divided into increasing inheritance and subtyping inheritance. The latter is studied and a behavioral subtyping inheritance is defined, by which the specification inheritance and its inference rules are defined. The soundness of the method is proved. The offered method is constructive compared with that of E. Cusack and is more flexible than that of Liskov et al.
Key wordsFormal method, object oriented, inheritance, subtyping, formal specification.
ʽ󷽷ѳΪоһҪ.90,ʽԼZΪоȵ,ȺɸZ汾1.COOZ(complete object-oriented Z)ڷZĻ,øΪȽļZ.
Zʹʽ󷽷,,OO༰ϵĹ켼ʹZͺ͸ϵͳ,ͬʱZѧʹǿԶԹԼͼ,Ա֤Լȷ.
̳󷽷Ҫĸ,̳һ棺Ϊ̳кʵּ̳.Ϊ̳мԼ̳,һǿͻ̳У2.һ.ʵּ̳м̳,ͨ޸е,,˸úʹ빲.ʵͻʱжַ,ͨʵּ̳Լʵͻ,Լһͨ͹3.ЩԼʹӦͶ̬ʱ³д,ܱ֤ϵһ.
ǶͻĿڣ֪Ժ͹,ĹԼ,ʱ,ֱ֪Ϣ,ǿԸϵͳܽ.,ΪʹͶиԺΪ,֤ͶԴ游,ʹΪһ־ֶ.,֤COOZԼ֤ģԣ2.,m֤ԸͶԼ,Ͷ游Ͷʱ,Լı,ʱ,Ӧ¹Լ֤m,ζŶԼ̳ԭд루ԼҪ֤.ǲҪ,Զһģ黯֤,һĻǹԼ̳.
COOZļ̳йϵ,Ѽ̳зΪͻַʽ,ֱʽ,ص۾нϴԵһͻ̳У˹Լ̳еķ.ͬʱ,˸÷ĺ.ΪùԼе͹ϵ,˻߼COOZ̳е.
1COOZ
COOZ4һʽԼ,еģʽclass schemaʾ:

ģʽбӿڡֲ塢״̬ģʽʼģʽģʽԼʾʵʱʷԼ಻ʽ,ģʽϸ﷨ף4.
ÿģʽAnonymous State Schema״̬ģʽԺ಻ʽ,״̬ռ,ڼ̳ʱ,״̬ģʽԶԺϲ.
ģʽжģʽ,ɽܵϢͨ䷽ģʽ˵,״̬ģʽԶķģʽ.ڼ̳ʱ,ͬģʽкϲԭ,ͬģʽкϲ,,ģʽϲĺģʽĺȡ5.
2COOZеļ̳Уͻ
ǰѼ̳зΪ̳кͻ̳.̳Ϊһϵ̳,ĻϹ,йԼĻ.ͻ̳һһĻ,Ϊľ.棬ǽֱּ̳,ΪԼʵC++*Ӧ,һֽΪ͡Ϊ͵ͻ̳з.
2.1̳С
̳еඨӡͱĹ.̳вܱ֤ĶҲǸĶ,ܱ֤Ǹ.Ǽ򻯲չCusack E6 ڼ̳еĶ.
A״̬ģʽΪSA,XAΪSA״̬ռ,OjΪAj.B״̬ģʽΪSB,XBΪSB״̬ռ,PjΪBj.SBΪSA ʵף6еĶ2,ӳfXBXA,SBʵӳ䵽SAʵ.Զ,OjɿXA֮ĹϵROj,Ȼ,ROjXAXA .ͬɵ,RPjXBXB.ӦأfɵӳffXBXBXAXA.ӦAķOjPjʽ,Ķ.
1. B״̬ģʽSBʵΪA״̬ģʽSAʵ,ӳfXBXA,BķPjʽ
R(Pj)ff=R(Oj)(XfBXfB)
BΪA,R(Pj)ffΪ,PjB޶.
1ǼΪϸļ̳ж,䶨಻޸ĸķ.ʵ,̳൱ں궨,ͨģʽļ̳ȫչΪʵ,ɵõûм̳йϵĹԼ.
2.2ͻ̳
E.Cusackͻ̳һַǹԷ,޸ĸ͵ķ.S.DrossoplouġSTTͻһּͻ,ͻ﷨Լ,Ա֤ͱʽ游ͱʽʱͲ,ܱ֤ͶΪ븸Ͷһ.ʵ,ͼֻܲ򲿷ִ,ȷܱ֤Ϊȷ.
Ϊ˴ﵽǰͻ3Ŀ,Ҫһ֡Ϊͻ,ͻ﷨Լ,ͻԼ.֤ͶΪ븸Ͷһ,֤Ͷ游Ͷʱ,ֳΪԼΪΪ.
Ϊ˱Ƚͺ͸,չף6еӳ.ڴ͹ϵļX,Y:XYšܱʾ͹ϵ,ģ⺯fXY:XY.Ҫжͻ̳,ҪȽ͵״̬ģʽ,ҪȽ͵ķģʽ.Ƚ͵״̬ģʽ,ǱȽ״̬ռеĲʽ,IXvzʾXĲʽ,vXʾXȡֵ.
Ϊ˱ȽϷģʽ,÷ֱʾS,Tķm,÷ֱʾS,Tķm.
ñʾSķmǰ,ñʾSķmĺ.ЦXʾXX,ǰı.һͻ̳еĶ.
2Ϊͻ̳У. SΪT,ҽ㣺
ʽ򣺶SֵvS


SĶthis:S,
(1) ǰ

(2) 

Ҫָ,ʽзӳ͹ϵԭcontravariance,ӳ͹ϵЭԭconvariance.
2.3ǿƹԼ̳
ʹCOOZԼʱ,Ϊ˱֤ʹü̳ʱԶ֤͹ϵ,Ǹ͹ϵĶ,һǿƹԼ̳еķ.Ȼ˼̳е,ȴ¿ʼ̸3ô,ʹùԼ̳,ǿƸͶķͶнȷĲ.,Ҫ۵,һͻΪ.Ϊʾ,šIʾ̳еĲʽ,pre,postֱʾ̳еǰ.ЩŵĶڵ3.2и.
3ǿƹԼ̳У. SΪ͵,SĹԼΪ
ʽ I(v):Is(v)ġI.
ǰ 
 
ֵע,ĶLiskov7ݵΧҪ,ͷڸͷ֮ȻЧ.
,ģʽֱʾͺ͵ķm,ǿƹԼ̳еĶ,ͷmĺΪ

ú̺ͷĺ,Ϊ,Ͷɴ游Ͷ.Ϊ˱ڱȽ,Liskov˵Ϊͻ̳еĶ.

SΪT,Ҫ
1 ʽ
2:
ǰ: 
: 
sΪS״̬,sʾ״̬,fʾģ⺯(2.2еĶ),Mxʾxеķ.
ɴ˿ɼǿƹԼ̳еķLiskov,E.CusackΪͻ̳еҪ.,Liskov,Ϊ,Ͷɴ游Ͷ.,ǿƹԼ̳еķڸԼʹü̳ʱṩ.,ڶmĵýʱ,ڸͶʱ,ͶmȻЧ.ͬʱͷĺ̺˸ͷĹԼ,ʹͷĹԼͶԶ,Ϊģ黯ṩ˻.
2.4ʵ
Ϊ˵Լ̳,һ򵥵ʵ.ģʽ(schema)BankAccountʾʻ,ģʽTwoAccountΪBankAccount,BankAccoountеcreditcurrencycheck.TwoAccountиϢ,Ϊ˱ָ͵ĹԼ,Ӧṩֵ븸Ӧĳֵϵģʽ.ֳģʽģ⺯simulation functionʾ,֮չΪϵ.Ϊ,ʵвģ⺯.R,StringΪ,ֱʾʵַ.

SimulationTwoAccountBankAccountģ⺯.ݹԼ̳,TwoAccountĲģʽWithdrawȫչʽΪ

selfʾTwoAccount.ѿ,Withdrawӳǰ涨ĹԼ̳.
3COOZм̳йϵ
COOZ,Z߼8,ص.,Ƚ,ȻصCOOZкͼ̳صĵ.
3.1߼
һGentzenʽʽ,Ͷʽʾ,ȻƵඨ.Ϊ˱ʾ,Ԫ,ЩԪڱ߼ⶨ.
ʽ
ʽʽΪd.
dΪ,Ϊνʼ,Ϊǰᡱ,Ҳνʼ,Ϊ.dĻ,νʾΪʱ,һνΪ,ʱ,ʽdЧ,ʵ൱ڦνʺȡ,νȡ.

ʽʽ

premissesΪǰ,ɸʽɣconclusionǵһʽ,ΪĽۣprovisoǹӦõĻбΪν,ΪЧ.proviso,premissesЧ,conclusionЧ,Ǻ.еnameڱʶù,Ϊ.
3.2Լ̳е
Ϊ۷,ȶ弸صԪ.Ԫַ̳еĸļ,S̳T1,...,Tn,Ц(S)=T1,...,Tn.Ԫеķ,̳еķ.
ʽI,pre,postĶ*.
̳еĲʽIĶ



̳еĲĶ
(1) ̳еǰ



(2) ̳еĺ

q1˵mT1,Tkеķ,mTk+1,Tn.
屣֤STiĹԼ̳еĹϵ,ֶΪģʽ(schema)״̬ģʽȡ().ΪCOOZԼеļ̳йϵ춨ۻ.
4Լ̳еĺ
ΪԼ̳еĺ,ǰʾľ9,еFrame ʾеķ

xʾڲзıı,Pʾν,ԱʾΪ.
COOZе͵ķΪ

±s,tֱʾͺ.Ȼ,ʽΪԼ̳еķģʽĶ.,x:pre,postݱʾ͵ķ,֤:

ɹԼ̳õ͵ķΪ͵,ɴ˿ԿĹԼ̳Ǻ.
ֵָ,Լ̳пΪྫֶ.ݽ.Լ̳ΪһΪ͵ķ,ܷʵеΪ,÷Ƿ걸,һо.
5ۺͽһо
COOZеļ̳йϵ,̳зΪ̳кͻ̳,صͻ̳.ǶһΪͻ̳,ݴ˶COOZĹԼ̳мԼ̳е.۵ͻE.Cusack˵ķ,пɹ,ұLiskov˵ķи.ʱʡˡԼ,ڼ̳пCOOZġʵʱʷԼֵо.,е,,ԱڹԼ֤мӦãҪһо.
Ʒ壨Ͼѧ¼صʵҡϾ210093
žѧѧԺϾ211101
ţϾѧ¼صʵҡϾ210093
֣Ͼѧ¼صʵҡϾ210093
ο
1Stepney S, Barden R, Cooper D. Object Orientation in Z. London: Springer-Verlag, 1992
2Dhara K K, Leavens G T. Forcing behavioral subtyping through specification inheritance. In: Kemmerer R A ed. Proceedings of the ICSE-18. Washington, DC: IEEE Press, 1996. 258267
3Drossopolou S, Karathanos S, Yang Dan. Static typing for object oriented language. In: Goldsack S J, Kent S J H eds. Formal Method and Object Technology. London: Springer-Verlag, 1996. 262286
4Yuan Xiao-dong, Hu De-qiang, Xu Hao et al. COOZ: a complete object-oriented extension to Z. ACM Software Engineering Notes, 1998,23(4):7881
5Spivey J M. The Z Notation: A Reference Manual. 2nd Edition, Series in Computer Science, London: Prentice-Hall, Inc., 1992
6Cusack E. Inheritance in object oriented Z. In: America P ed. Proceedings of the ECOOP'91. Volume 512 of Lecture Notes in Computer Science, New York: Springer-Verlag, 1991. 167179
7Liskov B, Wing J M. A behavioral notation of subtyping. ACM Transactions on Programming Languages and Systems, 1994,16(6):18111841
8Smith G. Extending of object-Z. In: Bowen J P, Hinchey M G ed. ZUM'95: the Z formal specification notation. Proceedings of the 9th Annual Z User Meeting, Volume 967 of Lecture Notes in Computer Science. London: Springer-Verlag, 1995. 276296
9Morgan C C, Gardiner P H B. Data refinement by calculation. Acta Information, 1990,27(6):481403
