2008年6月9日

OOP in REBOL 3.0: An Example

REBOL[]


Inherit: func [super [object!] sub [object!]] [
append sub reduce/no-set [parent: super]
]


Invoke: func [ obj member /local ans] [
either ans: select obj member [
ans
] [
attempt [Invoke obj/parent member]
]
]


Super-Class: context [
Member-A: does [ print "Member-A of Super" ]
Member-B: does [ print "Member-B of Super" ]
]


Sub-Class: context [
Inherit Super-Class Self


Member-B: does [ print "Member-B of Sub" ]
Member-C: does [ print "Member-C of Sub" ]
]


Invoke sub-class 'Member-A
Invoke sub-class 'Member-B
Invoke sub-class 'Member-C

2 則留言:

匿名 提到...

有個想法,REBOL 的作者是不是很不喜歡用到 Shift 鍵呀?怎麼都是使用 [ ]?

蔡學鏞 / Jerry Tsai 提到...

搞不好是這樣! :-)