Delegates: Difference between revisions

Added Julia language
(Adds Clojure solution)
(Added Julia language)
Line 1,216:
document.write(a.operation() + "\n") ;
}</lang>
 
=={{header|Julia}}==
'''Module''':
<lang julia>module Delegates
 
export Delegator, Delegate
 
struct Delegator{T}
delegate::T
end
 
struct Delegate end
 
operation(x::Delegator) = thing(x.delegate)
thing(::Any) = "default implementation"
thing(::Delegate) = "delegate implementation"
 
end # module Delegates</lang>
 
'''Main''':
<lang julia>using .Delegates
 
a = Delegator(nothing)
b = Delegator("string")
 
d = Delegate()
c = Delegator(d)
 
@show Delegates.operation(a)
@show Delegates.operation(b)
@show Delegates.operation(c)</lang>
 
{{out}}
<pre>Delegates.operation(a) = "default implementation"
Delegates.operation(b) = "default implementation"
Delegates.operation(c) = "delegate implementation"</pre>
 
=={{header|Kotlin}}==
Anonymous user