Skip to content

Instantly share code, notes, and snippets.

@Kikimora
Last active June 11, 2020 12:39
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Kikimora/caabc63bce6a3723790046a13e4ec17e to your computer and use it in GitHub Desktop.
/Suppose we have few expressions in and parser in library.dll
interface Exp { string Eval(); }
interface IntExp : Exp {}
interface AddExp : Exp {}
public interface IParser { Exp Parse(String s); }
public class ParserImpl : IParser { Exp Parse(String s); }
public static class ParserProvider { public static IParser GetParser() => new ParserImpl(); }
//There is client.dll
public static class Client
{
public static void Main(string[] args)
{
var e = ParserProvider.GetParser().Parse(s[0]);
Console.WriteLine(e.Eval());
}
}
//======= Suppose we want to add BoolExp with Multimethods =======
//(1) Add bool exp
interface BoolExp : Exp {}
//(2) Modify parser to support bool. ParserProvider returns modified parser.
public class ParserImpl : IParser { Exp Parse(String s); }
//DONE, client code remains same, just change library version.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment