Interfaces in Go are very powerful, but their power comes from being generic. Unlike interfaces in Java or C# where an interfaces defines a very specific thing that just lacks an implementation.
Russ Cox has a really good blog post about how go interfaces are implemented. Effective Go also has a section on go interfaces.
SharpDelegation is a Go interface feature implementation of C#,it depends on delegate and reflection.
##Getting Started
public class FlyBehavior
{
public delegate string _Fly();
public _Fly Fly { get; set; }
}
or
public class QuackBehavior : Delegation
{
public QuackBehavior() { }
public QuackBehavior(Type implementation)
{
Parse(this, implementation);
}
public delegate string _Quack();
public _Quack Quack { get; set; }
}
public class FlyWithWing
{
public string Fly()
{
return "Fly with wing, ";
}
}
public class FlyNoWay
{
public string Fly()
{
return "Fly no way, ";
}
}
public class Quacks
{
public string Quack()
{
return "Quack Quack Quack.";
}
}
public class Squeak
{
public string Quack()
{
return "Squeak Squeak Squeak.";
}
}
public class MuteQuack
{
public string Quack()
{
return "Mute Quack.";
}
}
or
public class FlyAndQuack
{
public string Fly()
{
return "Fly with wing.";
}
public string Quack()
{
return "Quack Quack Quack.";
}
}
FlyBehavior fly = Delegation.New<FlyBehavior>(typeof(FlyWithWing));
fly.Fly();
fly = Delegation.New<FlyBehavior>(typeof(FlyNoWay));
fly.Fly();
QuackBehavior quack = new QuackBehavior(typeof(Squeak));
quack.Quack();
quack = new QuackBehavior(typeof(MuteQuack));
quack.Quack();
or
FlyBehavior fly = Delegation.New<FlyBehavior>(typeof(FlyAndQuack));
fly.Fly();
QuackBehavior quack = new QuackBehavior(typeof(FlyAndQuack));
quack.Quack();
##Copyright Copyright (c) 2012 Hyson Wu. All rights reserved.
##License Art Mustache is MIT Lisense