Anonymous user
Inheritance/Multiple: Difference between revisions
Lingo added
(added Io entry) |
(Lingo added) |
||
Line 637:
true
=={{header|Lingo}}==
Lingo does not support multiple inheritance. But its slightly idiosyncratic inheritance implementation based on "ancestors" allows to assign/change inheritance relations at runtime. So a similar (but not identical) effect can be achieved by something like this:
<lang lingo>-- parent script "Camera"
property resolution
on new (me)
me.resolution = "1024x768"
return me
end
on snap (me)
put "SNAP!"
end</lang>
<lang lingo>-- parent script "MobilePhone"
property ringtone
on new (me)
me.ringtone = "Bell"
return me
end
on ring (me, n)
repeat with i = 1 to n
put "RING!!!"
end repeat
end</lang>
<lang lingo>-- parent script "CameraPhone"
property ancestor
on new (me)
c = script("Camera").new()
p = script("MobilePhone").new()
-- make the Camera instance a parent of the MobilePhone instance
p.setProp(#ancestor, c)
-- make the MobilePhone instance a parent of this CameraPhone instance
me.ancestor = p
return me
end</lang>
Usage:
<lang lingo>cp = script("CameraPhone").new()
cp.snap()
-- "SNAP!"
cp.ring(3)
-- "RING!!!"
-- "RING!!!"
-- "RING!!!"
put cp.resolution
-- "1024x768"
put cp.ringtone
-- "Bell"</lang>
=={{header|Logtalk}}==
|