Created
November 4, 2011 19:30
-
-
Save hodzanassredin/1340260 to your computer and use it in GitHub Desktop.
traits through proxies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using Nemerle.Collections; | |
| using Nemerle.Text; | |
| using Nemerle.Utility; | |
| using Nemerle.DesignPatterns; | |
| using System; | |
| using System.Collections.Generic; | |
| using System.Console; | |
| using System.Linq; | |
| module Program | |
| { | |
| Main() : void | |
| { | |
| def strategyA = AOverride(); | |
| def strategyB = B(); | |
| def t = Test(strategyA, strategyB); | |
| def x = t.Add(1,1); | |
| def y = t.Minus(x,3); | |
| t.Out(y); | |
| _ = ReadLine(); | |
| } | |
| } | |
| public class Test : IA, IB | |
| { | |
| [ProxyPublicMembers()] | |
| a : A; | |
| [ProxyPublicMembers()] | |
| b : B; | |
| // Constructors | |
| public this(ina : A, inb: B) | |
| { | |
| a = ina; | |
| b = inb; | |
| } | |
| public Out(x : double) : void | |
| { | |
| WriteLine("Result " + x.ToString()); | |
| } | |
| } | |
| public interface IA{ | |
| Add( x : double, y : double ) : double; | |
| Out( x : double) : void; | |
| } | |
| public class A{ | |
| public virtual Add(x : double, y : double ) : double | |
| { | |
| x + y; | |
| } | |
| } | |
| public class AOverride : A{ | |
| public override Add(x : double, y : double ) : double | |
| { | |
| x + y + 1; | |
| } | |
| } | |
| public interface IB{ | |
| Minus( x : double, y : double ) : double; | |
| } | |
| public class B : IB{ | |
| public Minus(x : double, y : double ) : double { x - y; } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment