2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
26
Task/Inheritance-Multiple/Elena/inheritance-multiple-1.elena
Normal file
26
Task/Inheritance-Multiple/Elena/inheritance-multiple-1.elena
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#import system.
|
||||
|
||||
#symbol CameraFeature =
|
||||
{
|
||||
#method cameraMsg
|
||||
= "camera".
|
||||
}.
|
||||
|
||||
#class MobilePhone
|
||||
{
|
||||
#method mobileMsg
|
||||
= "phone".
|
||||
}
|
||||
|
||||
#class CameraPhone :: MobilePhone
|
||||
{
|
||||
#method => CameraFeature.
|
||||
}
|
||||
|
||||
#symbol program =
|
||||
[
|
||||
#var cp := CameraPhone new.
|
||||
|
||||
console writeLine:(cp cameraMsg).
|
||||
console writeLine:(cp mobileMsg).
|
||||
].
|
||||
27
Task/Inheritance-Multiple/Elena/inheritance-multiple-2.elena
Normal file
27
Task/Inheritance-Multiple/Elena/inheritance-multiple-2.elena
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#import system.
|
||||
#import system'dynamic.
|
||||
|
||||
#class CameraFeature
|
||||
{
|
||||
#method cameraMsg
|
||||
= "camera".
|
||||
}
|
||||
|
||||
#class MobilePhone
|
||||
{
|
||||
#method mobileMsg
|
||||
= "phone".
|
||||
}
|
||||
|
||||
#symbol CameraPhone =
|
||||
{
|
||||
new = MobilePhone new mix &into:(CameraFeature new).
|
||||
}.
|
||||
|
||||
#symbol program =
|
||||
[
|
||||
#var cp := CameraPhone new.
|
||||
|
||||
console writeLine:(cp cameraMsg).
|
||||
console writeLine:(cp mobileMsg).
|
||||
].
|
||||
12
Task/Inheritance-Multiple/Io/inheritance-multiple.io
Normal file
12
Task/Inheritance-Multiple/Io/inheritance-multiple.io
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
Camera := Object clone
|
||||
Camera click := method("Taking snapshot" println)
|
||||
|
||||
MobilePhone := Object clone
|
||||
MobilePhone call := method("Calling home" println)
|
||||
|
||||
CameraPhone := Camera clone
|
||||
CameraPhone appendProto(MobilePhone)
|
||||
|
||||
myPhone := CameraPhone clone
|
||||
myPhone click // --> "Taking snapshot"
|
||||
myPhone call // --> "Calling home"
|
||||
28
Task/Inheritance-Multiple/Kotlin/inheritance-multiple.kotlin
Normal file
28
Task/Inheritance-Multiple/Kotlin/inheritance-multiple.kotlin
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
interface Camera {
|
||||
val numberOfLenses : Int
|
||||
}
|
||||
|
||||
interface MobilePhone {
|
||||
fun charge(n : Int) {
|
||||
if (n >= 0)
|
||||
battery_level = (battery_level + n).coerceAtMost(100)
|
||||
}
|
||||
|
||||
var battery_level : Int
|
||||
}
|
||||
|
||||
data class CameraPhone(override val numberOfLenses : Int = 1, override var battery_level: Int) : Camera, MobilePhone
|
||||
data class TwinLensCamera(override val numberOfLenses : Int = 2) : Camera
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val c = CameraPhone(1, 50)
|
||||
println(c)
|
||||
c.charge(35)
|
||||
println(c)
|
||||
c.charge(78)
|
||||
println(c)
|
||||
println(listOf(c.javaClass.superclass) + c.javaClass.interfaces)
|
||||
val c2 = TwinLensCamera()
|
||||
println(c2)
|
||||
println(listOf(c2.javaClass.superclass) + c2.javaClass.interfaces)
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
class Camera {}
|
||||
class MobilePhone {}
|
||||
class CameraPhone : Camera, MobilePhone {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue