YAPC::EU 2018 Glasgow Update!

This commit is contained in:
Ingy döt Net 2018-08-17 15:15:24 +01:00
parent 22f33d4004
commit 4e2d22a71d
1170 changed files with 15042 additions and 3047 deletions

View file

@ -0,0 +1,44 @@
enum OTHER, OPERATION
function operation(object o)
integer rid = o[OPERATION]
if rid!=NULL then
return call_func(rid,{})
end if
return "no implementation"
end function
function xthing()
return "default implementation"
end function
function newX()
return {1,routine_id("xthing"),2}
end function
function newY()
object res = newX()
res[OTHER] = "something else"
-- remove delegate:
res[OPERATION] = NULL
return res
end function
function zthing()
return "delegate implementation"
end function
function newZ()
object res = newX()
-- replace delegate:
res[OPERATION] = routine_id("zthing")
return res
end function
object x = newX(),
y = newY(),
z = newZ()
?operation(x)
?operation(y)
?operation(z)

View file

@ -0,0 +1,7 @@
?operation(x)
try -- (since rid=NULL check commented out)
?operation(y)
catch e
?"oops, no implementation"
end try
?operation(z)

View file

@ -0,0 +1,32 @@
trait Thingable {
def thing: String
}
class Delegator {
var delegate: Thingable = _
def operation: String = if (delegate == null) "default implementation"
else delegate.thing
}
class Delegate extends Thingable {
override def thing = "delegate implementation"
}
// Example usage
// Memory management ignored for simplification
object DelegateExample extends App {
val a = new Delegator
assert(a.operation == "default implementation")
// With a delegate:
val d = new Delegate
a.delegate = d
assert(a.operation == "delegate implementation")
// Same as the above, but with an anonymous class:
a.delegate = new Thingable() {
override def thing = "anonymous delegate implementation"
}
assert(a.operation == "anonymous delegate implementation")
}