Inheritance/Multiple: Difference between revisions
Content added Content deleted
(Added Wren) |
|||
Line 929: | Line 929: | ||
Module CheckIt { |
Module CheckIt { |
||
Class Camera { |
Class Camera { |
||
Private: |
|||
⚫ | |||
⚫ | |||
module Camera (.cameratype$){ |
|||
⚫ | |||
} |
} |
||
\\ INHERITANCE AT CODE LEVEL |
|||
Class MobilePhone { |
Class MobilePhone { |
||
Private: |
|||
⚫ | |||
model$ |
|||
Class: |
|||
module MobilePhone (.model$) { |
|||
} |
|||
} |
} |
||
Class CameraPhone { |
Class CameraPhone as Camera as MobilePhone { |
||
Module CameraPhone { |
Module CameraPhone ( .model$, .cameratype$) { |
||
\\ we can use : This=Camera() : This=MobilePhone() |
|||
\\ but we have to use Final for Functions/Modules in This |
|||
\\ So using M, a new local variable, we can accumulate Inheritance |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} |
} |
||
} |
} |
||
CP1=CameraPhone() |
CP1 =CameraPhone("X-15", "OBSCURE") |
||
Print |
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$ |
|||
⚫ | |||
Print "Nothing to print" |
|||
⚫ | |||
} |
|||
} |
|||
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 |
CheckIt |