Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
11
Task/Delegates/Zkl/delegates-1.zkl
Normal file
11
Task/Delegates/Zkl/delegates-1.zkl
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
class Thingable{ var thing; }
|
||||
|
||||
class Delegator{
|
||||
var delegate;
|
||||
fcn operation{
|
||||
if (delegate) delegate.thing;
|
||||
else "default implementation"
|
||||
}
|
||||
}
|
||||
|
||||
class Delegate(Thingable){ thing = "delegate implementation" }
|
||||
7
Task/Delegates/Zkl/delegates-2.zkl
Normal file
7
Task/Delegates/Zkl/delegates-2.zkl
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
// Without a delegate:
|
||||
a:= Delegator();
|
||||
a.operation().println(); //--> "default implementation"
|
||||
|
||||
// With a delegate:
|
||||
a.delegate = Delegate();
|
||||
a.operation().println(); //-->"delegate implementation"
|
||||
6
Task/Delegates/Zkl/delegates-3.zkl
Normal file
6
Task/Delegates/Zkl/delegates-3.zkl
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
class [static] Logger{ // Only one logging resource
|
||||
var [mixin=File] dst; // File like semantics, eg Data, Pipe
|
||||
dst = File.DevNull;
|
||||
// initially, the logger does nothing
|
||||
fcn log(msg){dst.writeln(vm.pasteArgs())}
|
||||
}
|
||||
6
Task/Delegates/Zkl/delegates-4.zkl
Normal file
6
Task/Delegates/Zkl/delegates-4.zkl
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
Logger.log("this is a test"); //-->nada
|
||||
Logger.dst=Console;
|
||||
Logger.log("this is a test 2"); //-->writes to Console
|
||||
|
||||
class B(Logger){ log("Hello from ",self,"'s constructor"); }
|
||||
B(); //-->Hello from Class(B)'s constructor
|
||||
Loading…
Add table
Add a link
Reference in a new issue