Last active
June 11, 2020 12:39
-
-
Save Kikimora/caabc63bce6a3723790046a13e4ec17e to your computer and use it in GitHub Desktop.
This file contains 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
/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