Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
40
Task/Delegates/Pluto/delegates.pluto
Normal file
40
Task/Delegates/Pluto/delegates.pluto
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
class thingable
|
||||
function thing() end
|
||||
end
|
||||
|
||||
-- Delegate that doesn't implement thingable.
|
||||
class delegate
|
||||
function __construct() end
|
||||
end
|
||||
|
||||
-- Delegate that implements thingable.
|
||||
class delegate2 extends thingable
|
||||
function __construct() end
|
||||
|
||||
function thing() return "delegate implementation" end
|
||||
end
|
||||
|
||||
class delegator
|
||||
function __construct()
|
||||
self.delegate = nil
|
||||
end
|
||||
|
||||
function operation()
|
||||
if !self.delegate or !(self.delegate instanceof thingable) then
|
||||
return "default implementation"
|
||||
end
|
||||
return self.delegate:thing()
|
||||
end
|
||||
end
|
||||
|
||||
-- Without a delegate.
|
||||
local d = new delegator()
|
||||
print(d:operation())
|
||||
|
||||
-- With a delegate that doesn't implement thingable.
|
||||
d.delegate = new delegate()
|
||||
print(d:operation())
|
||||
|
||||
-- With a delegate that does implement thingable.
|
||||
d.delegate = new delegate2()
|
||||
print(d:operation())
|
||||
Loading…
Add table
Add a link
Reference in a new issue