RosettaCodeData/Task/Inheritance-Multiple/M2000-Interpreter/inheritance-multiple.m2000
2026-04-30 12:34:36 -04:00

97 lines
2.5 KiB
Text

Module CheckIt {
Class Camera {
Private:
cameratype$
Class:
module Camera (.cameratype$){
}
}
\\ INHERITANCE AT CODE LEVEL
Class MobilePhone {
Private:
model$
Class:
module MobilePhone (.model$) {
}
}
Class CameraPhone as Camera as MobilePhone {
Module CameraPhone ( .model$, .cameratype$) {
}
}
CP1 =CameraPhone("X-15", "OBSCURE")
Print CP1 is type CameraPhone = true
Print CP1 is type Camera = true
Print CP1 is type MobilePhone = true
\\ INHERITANCE AT OBJECT LEVEL
CP2 = MobilePhone("X-9") with Camera("WIDE")
\\ CP3 has no type
Group CP3 {
Module PrintAll {
If this is type Camera and this is type MobilePhone then
Print .model$, .cameratype$
Else
Print "Nothing to print"
End if
}
}
CP3.PrintAll ' Nothing to print
\\ using pointers and prepate inheritance at object level
CP->(CP1 with CP3)
CP=>PrintAll
CP->(CP2 with CP3)
CP=>PrintAll
}
CheckIt
' like c++
Module CheckIt {
Class Camera {
Property cameratype$ {
value,
set {
read value$
if value$="" then Error "Null value not accepted"
}
}
Class:
module Camera (.cameratype$){
}
}
\\ INHERITANCE AT CODE LEVEL
Class MobilePhone {
Property model$ {
value,
set {
read value$
if value$="" then Error "Null value not accepted"
}
}
Class:
module MobilePhone (.model$) {
}
}
Class CameraPhone {
{
' these are local variables, not object's variables
Read model$, cameratype$
}
' we use these variable$ here:
Camera Gadget(model$)
MobilePhone Device(cameratype$)
}
' you can't pass null
CP1=CameraPhone("X-15", "OBSCURE")
Print CP1 is type CameraPhone = true
Print CP1 is type Camera = false
Print CP1 is type MobilePhone = false
Print CP1.Device.model$;" "; CP1.Gadget.cameratype$
Try ok {
' we get error
CP2=CameraPhone("X-15", "")
}
If Error Then Print Error$
}
CheckIt