Skip to content

Instantly share code, notes, and snippets.

@programmation
Created May 4, 2015 04:26
Show Gist options
  • Save programmation/2b5e567d83ad0f5fbb2d to your computer and use it in GitHub Desktop.
Save programmation/2b5e567d83ad0f5fbb2d to your computer and use it in GitHub Desktop.
Protocol pattern in C#
// http://www.knowing.net/index.php/2014/07/10/
interface IFoo
{
//Methods defined here, as always, must be implemented
void Necessary ();
}
static class IFoo_Extensions
{
//"Optional" methods defined here with default implementations
public static void Optional (this IFoo self)
{
}
}
class ImplementingClass : IFoo
{
public void Necessary ()
{
Console.WriteLine ("Necessary");
}
// public void Optional()
// {
// Console.WriteLine("Overridden");
// }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment