Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
5
Task/Inheritance-Multiple/Ada/inheritance-multiple.adb
Normal file
5
Task/Inheritance-Multiple/Ada/inheritance-multiple.adb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
package Multiple_Interfaces is
|
||||
type Camera is tagged null record;
|
||||
type Mobile_Phone is limited Interface;
|
||||
type Camera_Phone is new Camera and Mobile_Phone with null record;
|
||||
end Multiple_Interfaces;
|
||||
21
Task/Inheritance-Multiple/COBOL/inheritance-multiple.cob
Normal file
21
Task/Inheritance-Multiple/COBOL/inheritance-multiple.cob
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
IDENTIFICATION DIVISION.
|
||||
CLASS-ID. Camera.
|
||||
*> ...
|
||||
END CLASS Camera.
|
||||
|
||||
IDENTIFICATION DIVISION.
|
||||
CLASS-ID. Mobile-Phone.
|
||||
*> ...
|
||||
END CLASS Mobile-Phone.
|
||||
|
||||
IDENTIFICATION DIVISION.
|
||||
CLASS-ID. Camera-Phone
|
||||
INHERITS FROM Camera, Mobile-Phone.
|
||||
ENVIRONMENT DIVISION.
|
||||
CONFIGURATION SECTION.
|
||||
REPOSITORY.
|
||||
CLASS Camera
|
||||
CLASS Mobile-Phone.
|
||||
|
||||
*> ...
|
||||
END CLASS Camera-Phone.
|
||||
|
|
@ -43,3 +43,55 @@ Module CheckIt {
|
|||
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
|
||||
|
|
|
|||
21
Task/Inheritance-Multiple/Pluto/inheritance-multiple.pluto
Normal file
21
Task/Inheritance-Multiple/Pluto/inheritance-multiple.pluto
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
class Camera
|
||||
function snap() print("taking a photo") end
|
||||
end
|
||||
|
||||
class Phone
|
||||
function call() print("calling home") end
|
||||
end
|
||||
|
||||
class Cameraphone extends Camera
|
||||
function __construct(public phone) end -- uses composition for the Phone part
|
||||
|
||||
-- Inherits Camera's snap() method.
|
||||
|
||||
-- Phone's call() method can be wrapped.
|
||||
function call() self.phone:call() end
|
||||
end
|
||||
|
||||
local p = new Phone()
|
||||
local cp = new Cameraphone(p)
|
||||
cp:snap()
|
||||
cp:call()
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
class Camera {}
|
||||
class MobilePhone {}
|
||||
class CameraPhone : Camera, MobilePhone {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue