Created
May 4, 2015 04:26
-
-
Save programmation/2b5e567d83ad0f5fbb2d to your computer and use it in GitHub Desktop.
Protocol pattern in C#
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
// 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