Skip to content

Instantly share code, notes, and snippets.

@hodzanassredin
Created May 26, 2014 12:51
Show Gist options
  • Save hodzanassredin/3a4de5e03280ecc7d268 to your computer and use it in GitHub Desktop.
Save hodzanassredin/3a4de5e03280ecc7d268 to your computer and use it in GitHub Desktop.
version of previous gist to languge without generics, methods but with procedural pointers like oberon
using System;
namespace Test
{
public class TestTrait{//this class is not required but it reduces loc
public readonly Test Self;
public TestTrait (Test self){Self = self;}
}
public class A : TestTrait
{
public string Prop {get;set;}
public A (Test self, string prop): base(self){
Prop = prop;
Foo = () => Console.WriteLine("A.Foo " + this.Prop);
}
public Action Foo;
}
public class B : TestTrait
{
public B (Test self) : base(self){}
public Action Bar = () => Console.WriteLine("B.Bar");
}
public class C : TestTrait
{
public C (Test self, Func<A> aTrait, string aProp): base(self){
Add = () => {
Console.WriteLine ("add with a foo");
aTrait().Foo ();
};
}
public Action Bar = () => Console.WriteLine("B.Bar");
public Action Add;
}
public class Test{
public class ATrait: A{
public ATrait (Test self, Func<B> getBTrait, string prop) : base(self, prop){}
}
public class BTrait: B{
public BTrait (Test self) : base(self){}
}
public class CTrait: C{
public CTrait (Test self, Func<A> aTrait, string aProp) : base(self, aTrait, aProp){}
}
public Test ()
{
A = new ATrait (this, () => B, "a prop val");
B = new BTrait(this);
C = new CTrait (this, () => A, "c prop val");
}
public ATrait A { get ; set ;}
public BTrait B { get ; set ;}
public CTrait C { get ; set ;}
public void DoTests(){
Console.WriteLine ("Test");
}
}
class MainClass
{
public static void Main (string[] args)
{
var t = new Test ();
var a = t.A;
a.Foo();
var b = t.B;
b.Bar();
var c = t.C;
c.Add();
c.Self.DoTests ();
Console.ReadKey ();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment